Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abstract-leveldown

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-leveldown

An abstract prototype matching the LevelDOWN API

  • 0.12.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is abstract-leveldown?

abstract-leveldown is a foundational library for creating LevelDB-compatible stores. It provides a common interface for implementing custom storage backends, allowing developers to create their own LevelDB-like databases with different storage mechanisms.

What are abstract-leveldown's main functionalities?

Basic Operations

This code demonstrates how to create a custom storage backend by extending the AbstractLevelDOWN class. It includes basic operations like open, put, get, and delete.

const AbstractLevelDOWN = require('abstract-leveldown');

class MyCustomStore extends AbstractLevelDOWN {
  _open(options, callback) {
    // Custom open logic
    callback(null);
  }

  _put(key, value, options, callback) {
    // Custom put logic
    callback(null);
  }

  _get(key, options, callback) {
    // Custom get logic
    callback(null, 'value');
  }

  _del(key, options, callback) {
    // Custom delete logic
    callback(null);
  }
}

const store = new MyCustomStore('location');
store.open(() => {
  store.put('key', 'value', (err) => {
    if (!err) {
      store.get('key', (err, value) => {
        console.log(value); // 'value'
      });
    }
  });
});

Batch Operations

This code demonstrates how to implement batch operations in a custom storage backend. Batch operations allow multiple put and delete actions to be performed atomically.

const AbstractLevelDOWN = require('abstract-leveldown');

class MyCustomStore extends AbstractLevelDOWN {
  _batch(operations, options, callback) {
    // Custom batch logic
    callback(null);
  }
}

const store = new MyCustomStore('location');
store.open(() => {
  store.batch([
    { type: 'put', key: 'key1', value: 'value1' },
    { type: 'put', key: 'key2', value: 'value2' },
    { type: 'del', key: 'key3' }
  ], (err) => {
    if (!err) {
      console.log('Batch operations completed');
    }
  });
});

Iterator Support

This code demonstrates how to implement an iterator in a custom storage backend. Iterators are used to traverse the key-value pairs in the store.

const AbstractLevelDOWN = require('abstract-leveldown');

class MyCustomStore extends AbstractLevelDOWN {
  _iterator(options) {
    // Custom iterator logic
    return {
      next: (callback) => {
        // Custom next logic
        callback(null, 'key', 'value');
      },
      end: (callback) => {
        // Custom end logic
        callback(null);
      }
    };
  }
}

const store = new MyCustomStore('location');
store.open(() => {
  const iterator = store.iterator();
  iterator.next((err, key, value) => {
    console.log(key, value); // 'key', 'value'
    iterator.end(() => {
      console.log('Iterator ended');
    });
  });
});

Other packages similar to abstract-leveldown

Keywords

FAQs

Package last updated on 20 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc