https://github.com/badsyntax/react-native-lmdb
React Native bindings for LMDB (WIP)
https://github.com/badsyntax/react-native-lmdb
lmdb react-native
Last synced: 6 months ago
JSON representation
React Native bindings for LMDB (WIP)
- Host: GitHub
- URL: https://github.com/badsyntax/react-native-lmdb
- Owner: badsyntax
- License: mit
- Created: 2023-11-19T12:20:29.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-26T20:06:36.000Z (almost 2 years ago)
- Last Synced: 2025-03-16T01:18:35.180Z (7 months ago)
- Topics: lmdb, react-native
- Language: C++
- Homepage:
- Size: 1.67 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-lmdb
![]()
[LMDB](https://www.symas.com/lmdb) (Lightning Memory-Mapped Database) is an embedded transactional database in the form of a key-value store.
This package embeds & provides React Native bindings for LMDB.
_NOTE: Under development, not ready for consumption yet!_
## Installation
```sh
npm install react-native-lmdb
cd ios && pod install
```## Usage
```js
import { open } from 'react-native-lmdb';// Define the largest size of the db (100mb in this case)
const mapSize = 1024 * 1024 * 100;const { put, get, del } = open('mydb.mdb', mapSize);
put('key1', 'value1');
put('key2', 'value2');console.log(get('key1'));
console.log(get('key2'));del('key1');
del('key2');
```## Optimisation
LMDB uses transactions for read/write ops. Batch ops should use a shared transaction to improve perf.
Write lots of data in a single transaction:
```ts
const tidx = beginTransaction(true);
put('some', 'data', tidx);
put('other', 'data', tidx);
// ...
writeTransaction(tidx); // write the data to the db
```For reading data, you can use a global read transaction, then reset it to sync with the db.
```ts
// Make this global, and adjust all get() calls to use this transaction
const tidx = beginTransaction();const value1 = get('key1', tidx);
const value2 = get('key2', tidx);// Elsewhere in your app, after making changes to your db...
put('key1', 'new data');
resetTransaction(tidx); // this allow subsequent get() calls to use the latest db snapshotconst value1New = get('key1', tidx);
```## Motivation
MMKV is a great tool but isn't designed for vast amounts of data.
SQLite can handle vast amounts of data but is async thus increases complexity and introduces possible race conditions.
LMDB is mature, synchronous, and can handle anything you throw at it. 💪
## Goals of this Project
- Simple API
- Performance over features## Benchmarks
I am still in the process of profiling and optimising.
## Credits
- Thanks to [sysmas](https://www.symas.com/) for open sourcing lmdb.
## Donate
If you find LMDB useful please consider supporting the OpenLDAP foundation: https://www.openldap.org/foundation/
## Contributing
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
## License
MIT
---
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
```
```