MCPcopy Create free account
hub / github.com/ElementsProject/lightning / Sqlite3Rewriter

Class Sqlite3Rewriter

devtools/sql-rewrite.py:38–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37
38class Sqlite3Rewriter(Rewriter):
39 def rewrite_single(self, query):
40 # Replace DB specific queries with a no-op
41 if "/*PSQL*/" in query:
42 return "UPDATE vars SET intval=1 WHERE name='doesnotexist'" # Return a no-op
43
44 typemapping = {
45 r'BIGINT': 'INTEGER',
46 r'BIGINTEGER': 'INTEGER',
47 r'BIGSERIAL': 'INTEGER',
48 r'VARCHAR(?:\(\d+\))?': 'TEXT',
49 r'\bINT\b': 'INTEGER',
50 r'CURRENT_TIMESTAMP\(\)': "strftime('%s', 'now')",
51 r'INSERT INTO[ \t]+(.*)[ \t]+ON CONFLICT.*DO NOTHING;': 'INSERT OR IGNORE INTO \\1;',
52 # Rewrite "decode('abcd', 'hex')" to become "x'abcd'"
53 r'decode\((.*),\s*[\'\"]hex[\'\"]\)': 'x\\1',
54 # GREATEST() of multiple columns is simple MAX in sqlite3.
55 r'GREATEST\(([^)]*)\)': "MAX(\\1)",
56 # NULLS FIRST is default behavior on sqlite, make it disappear
57 r' NULLS FIRST': '',
58 }
59 return self.rewrite_types(query, typemapping)
60
61
62class PostgresRewriter(Rewriter):

Callers 1

sql-rewrite.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected