fdb - kv Database, power failure does not lose data#

Adapted Air780E/Air700E Air780EP Air601 Air101/Air103 Air105 ESP32C3 ESP32S3

Note

This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!

Tip

This library has its own demo,click this link to view the demo example of fdb

Example

-- This library has been abandoned, fskv library is recommended.

fdb.kvdb_init(name, partition)#

Initialize the kv database

Parameters

Incoming Value Type

Explanation

string

Database name, currently only supported env

string

FAL Partition name, currently only supported onchip_fdb

Return Value

return value type

explanation

boolean

Returns true on success, otherwise false

Examples

-- fdb Library based on flashdb, thanks again.
if fdb.kvdb_init("env", "onchip_fdb") then
    log.info("fdb", "kv Database initialization successful")
end

-- About emptying the fdb library
-- The download tool does not provide a way to directly clear fdb data, but there are ways to solve it.
-- Write a main.lua, execute fdb.kvdb_init and then execute fdb.clear() to clear fdb data..

fdb.kv_set(key, value)#

set a pair of kv data

Parameters

Incoming Value Type

Explanation

string

key Name of, required, cannot be empty string

string

User data, required, cannot be nil, supports string/value/table/boolean, data length up to 255 bytes

Return Value

return value type

explanation

boolean

Returns true on success, otherwise false

number

The second returns the detailed status for the fdb_kv_set_blob returned as flashdb, 0: no error 1: erase error 2: read error 3: write error 4: not found 5:kv name error 6:kv name exists 7: saved 8: initialization error

Examples

if fdb.kvdb_init("env", "onchip_fdb") then
    log.info("fdb", fdb.kv_set("wendal", "goodgoodstudy"))
end

fdb.kv_get(key, skey)#

Obtain the corresponding data according to the key.

Parameters

Incoming Value Type

Explanation

string

key Name of, required, cannot be empty string

string

Optional secondary key, valid only when the original value is table, equivalent fdb.kv_get(key)[skey]

Return Value

return value type

explanation

any

Returns data if it exists, otherwise nil

Examples

if fdb.kvdb_init("env", "onchip_fdb") then
    log.info("fdb", fdb.kv_get("wendal"))
end

fdb.kv_del(key)#

Delete data based on key

Parameters

Incoming Value Type

Explanation

string

key Name of, required, cannot be empty string

Return Value

return value type

explanation

bool

Returns true on success, otherwise false

Examples

if fdb.kvdb_init("env", "onchip_fdb") then
    log.info("fdb", fdb.kv_del("wendal"))
end

fdb.kv_clr()#

empty the entire kv database

Parameters

None

Return Value

return value type

explanation

bool

Returns true on success, otherwise false

Examples

-- Empty
fdb.kv_clr()

fdb.kv_iter()#

kv Database Iterators

Parameters

None

Return Value

return value type

explanation

userdata

Returns an iterator pointer on success, otherwise nil

Examples

-- Empty
local iter = fdb.kv_iter()
if iter then
    while 1 do
        local k = fdb.kv_next(iter)
        if not k then
            break
        end
        log.info("fdb", k, "value", fdb.kv_get(k))
    end
end

fdb.kv_next(iter)#

kv Iterator to get the next key

Parameters

Incoming Value Type

Explanation

userdata

fdb.kv_iter()Pointer returned

Return Value

return value type

explanation

string

Returns the string key value on success, otherwise nil

Examples

-- Empty
local iter = fdb.kv_iter()
if iter then
    while 1 do
        local k = fdb.kv_next(iter)
        if not k then
            break
        end
        log.info("fdb", k, "value", fdb.kv_get(k))
    end
end

fdb.kv_stat()#

obtain kv database status

Parameters

None

Return Value

return value type

explanation

int

Space used in bytes

int

Total available space in bytes

int

total number of kv key-value pairs, units

Examples

-- This API was added on 2022.07.23
local used,maxs,kv_count = fdb.kv_stat()
log.info("fdb", "kv", used,maxs,kv_count)