Skip to content

Add the fdb_tsl_append_with_ts method to FlashDB #170

@Vadimatorik

Description

@Vadimatorik

Is your feature request related to a problem?

My project requires you to specify the time yourself when adding new values to the database. This feature is available in the original library. I'm asking you to add it to the next release.

Describe the solution you'd like.

Fixes in flashdb.h (added the timestamp parameter):

static fdb_err_t tsl_append(fdb_tsdb_t db, fdb_blob_t blob, fdb_time_t *timestamp)
{
    fdb_err_t result = FDB_NO_ERR;
    fdb_time_t cur_time = timestamp == NULL ? db->get_time() : *timestamp;

Fixes in the fdb_tsl_append method (add NULL to tsl_append):

/**
 * Append a new log to TSDB.
 *
 * @param db database object
 * @param blob log blob data
 *
 * @return result
 */
fdb_err_t fdb_tsl_append(fdb_tsdb_t db, fdb_blob_t blob)
{
    fdb_err_t result = FDB_NO_ERR;

    if (!db_init_ok(db)) {
        FDB_INFO("Error: TSL (%s) isn't initialize OK.\n", db_name(db));
        return FDB_INIT_FAILED;
    }

    db_lock(db);
    result = tsl_append(db, blob, NULL);
    db_unlock(db);

    return result;
}

Add the fdb_tsl_append_with_ts method:

/**
 * Append a new log to TSDB with specific timestamp.
 *
 * @param db database object
 * @param blob log blob data
 *
 * @return result
 */
fdb_err_t fdb_tsl_append_with_ts(fdb_tsdb_t db, fdb_blob_t blob, fdb_time_t timestamp)
{
    fdb_err_t result = FDB_NO_ERR;

    if (!db_init_ok(db)) {
        FDB_INFO("Error: TSL (%s) isn't initialize OK.\n", db_name(db));
        return FDB_INIT_FAILED;
    }

    db_lock(db);
    result = tsl_append(db, blob, &timestamp);
    db_unlock(db);

    return result;
}

Describe alternatives you've considered.

No response

Additional context.

All the changes are shown here:

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions