jnwatson / py-lmdb

Universal Python binding for the LMDB 'Lightning' Database
http://lmdb.readthedocs.io/
Other
646 stars 106 forks source link

lmdb-js compatibility issue #329

Closed pgmillon closed 2 years ago

pgmillon commented 2 years ago

Node v18.9.1 "lmdb": "^2.6.8" Alpine 3.16.12

Install py-lmdb in addition to node/lmdb-js:

# python3 -m ensurepip
# apk add g++ make patch
# python3 -m pip install lmdb

main.mjs

import { open } from 'lmdb';
let myDB = open({
    path:  'test.mdb',
    maxDbs: 1
});

let db = myDB.openDB('documents', {})
await db.put('key1', 'value1')

main.py

import lmdb

env = lmdb.open('test.mdb', max_dbs=1, subdir=False)

db = env.open_db('documents'.encode())

with env.begin(write=True) as txn:
    for key, value in txn.cursor(db):
        print(key, value)

If DB is created by lmdb-js I have a MDB_VERSION_MISMATCH: Database environment version mismatch on the Python side. If created by py-lmdb, I have a MDB_INVALID: File is not an LMDB file on the NodeJS side.

Seems both py-lmdb & lmdb-js uses LMDB 0.9.29 as of today.

pgmillon commented 2 years ago

Reported on lmdb-js: https://github.com/kriszyp/lmdb-js/issues/193

kriszyp commented 2 years ago

Followed up on lmdb-js, but also mentioning here that by default lmdb-js uses LMDB 0.9.90 (latest code), not 0.9.29 (latest release), which is definitely incompatible, so wouldn't expect py-lmdb to be compatible with that.

pgmillon commented 2 years ago

Problem solved by using a release of lmdb-js bundled with LMDB 0.9.29.