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

Class PostgresRewriter

devtools/sql-rewrite.py:62–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61
62class PostgresRewriter(Rewriter):
63 def rewrite_single(self, q):
64 # Replace DB specific queries with a no-op
65 if "/*SQLITE*/" in q:
66 return "UPDATE vars SET intval=1 WHERE name='doesnotexist'" # Return a no-op
67
68 # Let's start by replacing any eventual '?' placeholders
69 q2 = ""
70 count = 1
71 for c in q:
72 if c == '?':
73 c = "${}".format(count)
74 count += 1
75 q2 += c
76 query = q2
77
78 typemapping = {
79 r'BLOB': 'BYTEA',
80 r'_ROWID_': '(((ctid::text::point)[0]::bigint << 32) | (ctid::text::point)[1]::bigint)', # Yeah, I know...
81 r'CURRENT_TIMESTAMP\(\)': "EXTRACT(epoch FROM now())",
82 }
83
84 query = self.rewrite_types(query, typemapping)
85 return query
86
87
88rewriters = {

Callers 1

sql-rewrite.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected