aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: b4db24321abbd629665ee83c2e626df9748fd572 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# [LMDB](http://www.lmdb.tech/doc/index.html) bindings for lua
license: MIT

## errors
operations that can fail will return `nil, error, errno` on failure.

## functions
### `lmdb.open(path, opt)`
create a new environment handle and open the database at the `path`. returns the environment handle (`env`) on success.

`opt` is an optional table of options:

* `maxdbs`: number: the maximum number of databases in the environment. must be set if multiple databases will be used.
* `rdonly`: boolean: open the environment in read-only mode.
* `nosubdir`: boolean: the `path` is used for the database file itself and not its containing directory.
* `nosync`: boolean: don't flush buffers to disk when committing.
* `nolock`: boolean: turn off locking. the application must manage all concurrency.

### `lmdb.version()`
returns the LMDB version as `major, minor, patch`.

### `lmdb.next(db, key)`
returns the next key-value pair after `key` in the database handle `db`, or the first key-value pair if `key` is `nil`. keys are ordered lexicographically. unlike `next`, this function does not work for traversal if, during traversal, keys are set to `nil`. (TODO: fix this somehow)

### `env:txn_begin(write_enabled)`
create a new transaction in the environment. if `write_enabled` is true, then the transaction may make modifications to the database. returns the transaction handle (`txn`) on success.

### `env:copy(path)`
copy the environment to the specified `path`. return `true` on success.

### `env:sync(force)`
flush buffers to disk. if `force` is `true`, a synchronous flush is performed even if `nosync` is set. return `true` on success.

### `env:close()`
close the environment.

### `txn:open(name, create)`
open a database in the environment. if multiple databases are to be used in the environment, `name` is the name of the database to open. otherwise, it should not be supplied. if `create` is true, the database is created if it does not exist. returns a database handle (`db`) on success.

### `txn:drop(name)`
delete the database `name` from the environment. (or clear the database, if `name` is not supplied)

### `txn:abort()`
abandon all operations performed in the transaction.

### `txn:commit()`
commit all operations of the transaction into the database.

### `txn:txn_begin()`
create a nested transaction in the parent transaction.

### `db[key]`
read the value of `key` from the database.

### `db[key] = value`
write `value` as the value of `key` into the database.

### `pairs(db)`, `lmdb.pairs(db)`
returns `lmdb.next, db, nil`, allowing iteration through all the key-value pairs of a database. the `lmdb.pairs` form works even on lua 5.1, which doesn't support the `__pairs` metamethod.

### `#db`
return the number of entries in the database.