mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
db: Make the db struct private and provide accessors instead
We will soon generalize the DB, so directly reaching into the `struct db` instance to talk to the sqlite3 connection is bad anyway. This increases flexibility and allows us to tailor the actual implementation to the underlying DB. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
66a47d2761
commit
803007ecdf
22
wallet/db.c
22
wallet/db.c
@@ -23,6 +23,13 @@ struct migration {
|
||||
void (*func)(struct lightningd *ld, struct db *db);
|
||||
};
|
||||
|
||||
struct db {
|
||||
char *filename;
|
||||
const char *in_transaction;
|
||||
sqlite3 *sql;
|
||||
const char **changes;
|
||||
};
|
||||
|
||||
void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db);
|
||||
|
||||
/* Do not reorder or remove elements from this array, it is used to
|
||||
@@ -685,6 +692,21 @@ static void db_prepare_for_changes(struct db *db)
|
||||
db->changes = tal_arr(db, const char *, 0);
|
||||
}
|
||||
|
||||
bool db_in_transaction(struct db *db)
|
||||
{
|
||||
return db->in_transaction;
|
||||
}
|
||||
|
||||
u64 db_last_insert_id(struct db *db)
|
||||
{
|
||||
return sqlite3_last_insert_rowid(db->sql);
|
||||
}
|
||||
|
||||
size_t db_changes(struct db *db)
|
||||
{
|
||||
return sqlite3_changes(db->sql);
|
||||
}
|
||||
|
||||
void db_begin_transaction_(struct db *db, const char *location)
|
||||
{
|
||||
if (db->in_transaction)
|
||||
|
||||
Reference in New Issue
Block a user