mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
db: Extract db config lookup into its own function
Signed-off-by: Christian Decker <decker.christian@gmail.com> Suggested-by: Rusty Russell <@rustyrussell>
This commit is contained in:
parent
c6b6958ae6
commit
58f448904c
19
wallet/db.c
19
wallet/db.c
@ -647,6 +647,16 @@ static void setup_open_db(struct db *db)
|
||||
db_report_changes(db, NULL, 0);
|
||||
}
|
||||
|
||||
static struct db_config *db_config_find(const char *driver_name)
|
||||
{
|
||||
size_t num_configs;
|
||||
struct db_config **configs = autodata_get(db_backends, &num_configs);
|
||||
for (size_t i=0; i<num_configs; i++)
|
||||
if (streq(driver_name, configs[i]->name))
|
||||
return configs[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* db_open - Open or create a sqlite3 database
|
||||
*/
|
||||
@ -655,8 +665,6 @@ static struct db *db_open(const tal_t *ctx, char *filename)
|
||||
int err;
|
||||
struct db *db;
|
||||
sqlite3 *sql;
|
||||
size_t num_configs;
|
||||
struct db_config **configs = autodata_get(db_backends, &num_configs);
|
||||
const char *driver_name = "sqlite3";
|
||||
|
||||
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
||||
@ -670,13 +678,10 @@ static struct db *db_open(const tal_t *ctx, char *filename)
|
||||
db = tal(ctx, struct db);
|
||||
db->filename = tal_strdup(db, filename);
|
||||
db->sql = sql;
|
||||
db->config = NULL;
|
||||
list_head_init(&db->pending_statements);
|
||||
for (size_t i=0; i<num_configs; i++)
|
||||
if (streq(driver_name, configs[i]->name)) {
|
||||
db->config = configs[i];
|
||||
break;
|
||||
}
|
||||
|
||||
db->config = db_config_find(driver_name);
|
||||
if (!db->config)
|
||||
db_fatal("Unable to find DB driver for %s", driver_name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user