Top Related Projects
A command-line tool for Stripe
Quick Overview
Level is a fast and secure key-value database that is designed to be embedded in other applications. It is a simple and lightweight database that can be used as a replacement for traditional databases in certain use cases.
Pros
- Fast and Efficient: Level is designed to be fast and efficient, with low latency and high throughput.
- Secure: Level uses encryption to protect data at rest and in transit, ensuring the security of your data.
- Lightweight: Level is a small and lightweight database, making it easy to embed in other applications.
- Cross-Platform: Level is cross-platform and can be used on a variety of operating systems, including Windows, macOS, and Linux.
Cons
- Limited Functionality: Level is a key-value database, which means it has a limited set of features compared to more complex database systems.
- No Transactions: Level does not support transactions, which may be a limitation for certain use cases.
- No SQL Support: Level does not support SQL, which may be a limitation for developers who are more familiar with SQL-based databases.
- Limited Community: Level has a smaller community compared to some other database systems, which may make it more difficult to find support and resources.
Code Examples
Here are a few examples of how to use Level in your code:
// Open a new database
const db = level('path/to/database')
// Put a key-value pair
await db.put('key', 'value')
// Get a value by key
const value = await db.get('key')
// Delete a key-value pair
await db.del('key')
// Iterate over all keys in the database
const stream = db.createReadStream()
for await (const { key, value } of stream) {
console.log(`${key} = ${value}`)
}
// Use a batch operation to write multiple key-value pairs
await db.batch([
{ type: 'put', key: 'key1', value: 'value1' },
{ type: 'put', key: 'key2', value: 'value2' },
{ type: 'del', key: 'key3' }
])
Getting Started
To get started with Level, you can follow these steps:
- Install the Level package using your preferred package manager:
npm install level
- Create a new Level database and start using it in your code:
const level = require('level')
const db = level('path/to/database')
// Put a key-value pair
await db.put('key', 'value')
// Get a value by key
const value = await db.get('key')
// Delete a key-value pair
await db.del('key')
- Explore the Level API and documentation to learn more about the available features and functionality.
Competitor Comparisons
A command-line tool for Stripe
Pros of stripe-cli
- More comprehensive CLI tool for Stripe's ecosystem
- Actively maintained with frequent updates
- Extensive documentation and community support
Cons of stripe-cli
- Focused solely on Stripe, limiting its use for other payment platforms
- Steeper learning curve for users unfamiliar with Stripe's API
- Requires Stripe account and API keys for full functionality
Code Comparison
stripe-cli:
stripe listen --forward-to localhost:3000/webhook
stripe trigger payment_intent.succeeded
stripe samples create accept-a-payment
Level:
from level import Client
client = Client("your_api_key")
account = client.accounts.create(name="Example Account")
transaction = client.transactions.create(account_id=account.id, amount=1000)
Summary
stripe-cli is a powerful tool for Stripe developers, offering extensive features for managing Stripe integrations. However, it's limited to the Stripe ecosystem. Level provides a more general-purpose financial API client, which may be more suitable for projects requiring flexibility across different financial services. The choice between the two depends on the specific needs of your project and your preferred payment platform.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
level
Universal abstract-level
database for Node.js and browsers. This is a convenience package that exports classic-level
in Node.js and browser-level
in browsers, making it an ideal entry point to start creating lexicographically sorted key-value databases.
:pushpin: Which module should I use? What is
abstract-level
? Head over to the FAQ.
Usage
If you are upgrading: please see UPGRADING.md
.
const { Level } = require('level')
// Create a database
const db = new Level('example', { valueEncoding: 'json' })
// Add an entry with key 'a' and value 1
await db.put('a', 1)
// Add multiple entries
await db.batch([{ type: 'put', key: 'b', value: 2 }])
// Get value of key 'a': 1
const value = await db.get('a')
// Iterate entries with keys that are greater than 'a'
for await (const [key, value] of db.iterator({ gt: 'a' })) {
console.log(value) // 2
}
TypeScript type declarations are included and cover the methods that are common between classic-level
and browser-level
. Usage from TypeScript requires generic type parameters.
TypeScript example
// Specify types of keys and values (any, in the case of json).
// The generic type parameters default to Level<string, string>.
const db = new Level<string, any>('./db', { valueEncoding: 'json' })
// All relevant methods then use those types
await db.put('a', { x: 123 })
// Specify different types when overriding encoding per operation
await db.get<string, string>('a', { valueEncoding: 'utf8' })
// Though in some cases TypeScript can infer them
await db.get('a', { valueEncoding: db.valueEncoding('utf8') })
// It works the same for sublevels
const abc = db.sublevel('abc')
const xyz = db.sublevel<string, any>('xyz', { valueEncoding: 'json' })
Install
With npm do:
npm install level
For use in browsers, this package is best used with browserify
, webpack
, rollup
or similar bundlers. For a quick start, visit browserify-starter
or webpack-starter
.
Supported Platforms
At the time of writing, level
works in Node.js 18+ and Electron 30+ on Linux, Mac OS and Windows, including any future Node.js and Electron release thanks to Node-API, including ARM platforms like Raspberry Pi and Android, as well as in Chromium, Firefox and Safari. For details, see Supported Platforms of classic-level
and Browser Support of browser-level
.
Binary keys and values are supported across the board.
API
The API of level
follows that of abstract-level
. For additional options and methods specific to classic-level
or browser-level
, please see their respective READMEs. The documentation below only covers the common constructor.
db = new Level(location[, options])
Create a new database or open an existing database. The location
argument must be a directory path (relative or absolute) where LevelDB will store its files, or in browsers, the name of the IDBDatabase
to be opened.
Contributing
Level/level
is an OPEN Open Source Project. This means that:
Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
See the Contribution Guide for more details.
Donate
Support us with a monthly donation on Open Collective and help us continue our work.
License
Top Related Projects
A command-line tool for Stripe
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot