mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
postgres: Add postgres statement rewriting support
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
5953a5051c
commit
bf613fa48a
4 changed files with 46 additions and 3 deletions
|
@ -10,8 +10,12 @@ class Sqlite3Rewriter(object):
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
|
class PostgresRewriter(Sqlite3Rewriter):
|
||||||
|
pass
|
||||||
|
|
||||||
rewriters = {
|
rewriters = {
|
||||||
"sqlite3": Sqlite3Rewriter(),
|
"sqlite3": Sqlite3Rewriter(),
|
||||||
|
"postgres": PostgresRewriter(),
|
||||||
}
|
}
|
||||||
|
|
||||||
template = Template("""#ifndef LIGHTNINGD_WALLET_GEN_DB_${f.upper()}
|
template = Template("""#ifndef LIGHTNINGD_WALLET_GEN_DB_${f.upper()}
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
sqlparse==0.3.0
|
|
||||||
mako==1.0.14
|
mako==1.0.14
|
||||||
mrkd==0.1.5
|
mrkd==0.1.5
|
||||||
|
|
|
@ -12,6 +12,7 @@ WALLET_LIB_SRC := \
|
||||||
wallet/walletrpc.c
|
wallet/walletrpc.c
|
||||||
|
|
||||||
WALLET_DB_DRIVERS := \
|
WALLET_DB_DRIVERS := \
|
||||||
|
wallet/db_postgres.c \
|
||||||
wallet/db_sqlite3.c
|
wallet/db_sqlite3.c
|
||||||
|
|
||||||
WALLET_LIB_OBJS := $(WALLET_LIB_SRC:.c=.o) $(WALLET_DB_DRIVERS:.c=.o)
|
WALLET_LIB_OBJS := $(WALLET_LIB_SRC:.c=.o) $(WALLET_DB_DRIVERS:.c=.o)
|
||||||
|
@ -29,7 +30,9 @@ check-source-bolt: $(WALLET_LIB_SRC:%=bolt-check/%) $(WALLET_LIB_HEADERS:%=bolt-
|
||||||
|
|
||||||
clean: wallet-clean
|
clean: wallet-clean
|
||||||
|
|
||||||
|
# Each database driver depends on its rewritten statements.
|
||||||
wallet/db_sqlite3.c: wallet/gen_db_sqlite3.c
|
wallet/db_sqlite3.c: wallet/gen_db_sqlite3.c
|
||||||
|
wallet/db_postgres.c: wallet/gen_db_postgres.c
|
||||||
|
|
||||||
# The following files contain SQL-annotated statements that we need to extact
|
# The following files contain SQL-annotated statements that we need to extact
|
||||||
SQL_FILES := \
|
SQL_FILES := \
|
||||||
|
@ -42,12 +45,13 @@ SQL_FILES := \
|
||||||
wallet/statements.po: $(SQL_FILES)
|
wallet/statements.po: $(SQL_FILES)
|
||||||
xgettext -kNAMED_SQL -kSQL --add-location --no-wrap --omit-header -o $@ $(SQL_FILES)
|
xgettext -kNAMED_SQL -kSQL --add-location --no-wrap --omit-header -o $@ $(SQL_FILES)
|
||||||
|
|
||||||
wallet/gen_db_sqlite3.c: wallet/statements.po devtools/sql-rewrite.py
|
wallet/gen_db_%.c: wallet/statements.po devtools/sql-rewrite.py
|
||||||
devtools/sql-rewrite.py wallet/statements.po sqlite3 > wallet/gen_db_sqlite3.c
|
devtools/sql-rewrite.py wallet/statements.po $* > wallet/gen_db_$*.c
|
||||||
|
|
||||||
wallet-clean:
|
wallet-clean:
|
||||||
$(RM) $(WALLET_LIB_OBJS)
|
$(RM) $(WALLET_LIB_OBJS)
|
||||||
$(RM) wallet/statements.po
|
$(RM) wallet/statements.po
|
||||||
$(RM) wallet/gen_db_sqlite3.c
|
$(RM) wallet/gen_db_sqlite3.c
|
||||||
|
$(RM) wallet/gen_db_postgres.c
|
||||||
|
|
||||||
include wallet/test/Makefile
|
include wallet/test/Makefile
|
||||||
|
|
36
wallet/db_postgres.c
Normal file
36
wallet/db_postgres.c
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#include <wallet/db_common.h>
|
||||||
|
#include "gen_db_postgres.c"
|
||||||
|
#include <ccan/ccan/tal/str/str.h>
|
||||||
|
#include <lightningd/log.h>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#if HAVE_POSTGRES
|
||||||
|
|
||||||
|
struct db_config db_postgres_config = {
|
||||||
|
.name = "postgres",
|
||||||
|
.queries = NULL,
|
||||||
|
.num_queries = DB_POSTGRES_QUERY_COUNT,
|
||||||
|
.exec_fn = NULL,
|
||||||
|
.query_fn = NULL,
|
||||||
|
.step_fn = NULL,
|
||||||
|
.begin_tx_fn = NULL,
|
||||||
|
.commit_tx_fn = NULL,
|
||||||
|
.stmt_free_fn = NULL,
|
||||||
|
|
||||||
|
.column_is_null_fn = NULL,
|
||||||
|
.column_u64_fn = NULL,
|
||||||
|
.column_int_fn = NULL,
|
||||||
|
.column_bytes_fn = NULL,
|
||||||
|
.column_blob_fn = NULL,
|
||||||
|
.column_text_fn = NULL,
|
||||||
|
|
||||||
|
.last_insert_id_fn = NULL,
|
||||||
|
.count_changes_fn = NULL,
|
||||||
|
.setup_fn = NULL,
|
||||||
|
.teardown_fn = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
AUTODATA(db_backends, &db_postgres_config);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Reference in a new issue