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:
Christian Decker
2019-07-23 20:45:06 +02:00
committed by Rusty Russell
parent 66a47d2761
commit 803007ecdf
6 changed files with 46 additions and 16 deletions

View File

@@ -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)