fix: support postgres pragma table info
This commit is contained in:
@@ -64,6 +64,24 @@ function rewritePlaceholders(sql, params) {
|
|||||||
|
|
||||||
function rewriteSql(sql, params) {
|
function rewriteSql(sql, params) {
|
||||||
let text = String(sql).trim();
|
let text = String(sql).trim();
|
||||||
|
const pragmaTable = text.match(/^PRAGMA\s+table_info\((?:"([^"]+)"|'([^']+)'|([^)]+))\)$/i);
|
||||||
|
if (pragmaTable) {
|
||||||
|
const table = String(pragmaTable[1] || pragmaTable[2] || pragmaTable[3] || '').trim();
|
||||||
|
return {
|
||||||
|
sql: `
|
||||||
|
SELECT ordinal_position - 1 AS cid,
|
||||||
|
column_name AS name,
|
||||||
|
data_type AS type,
|
||||||
|
CASE WHEN is_nullable = 'NO' THEN 1 ELSE 0 END AS notnull,
|
||||||
|
column_default AS dflt_value,
|
||||||
|
0 AS pk
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_schema = current_schema() AND table_name = $1
|
||||||
|
ORDER BY ordinal_position
|
||||||
|
`,
|
||||||
|
params: [table],
|
||||||
|
};
|
||||||
|
}
|
||||||
text = text.replace(/INSERT\s+OR\s+IGNORE\s+INTO/gi, 'INSERT INTO');
|
text = text.replace(/INSERT\s+OR\s+IGNORE\s+INTO/gi, 'INSERT INTO');
|
||||||
text = text.replace(/INSERT\s+OR\s+REPLACE\s+INTO\s+autonomy_outcomes\s*\(([^)]+)\)\s*VALUES\s*\(([^)]+)\)/i,
|
text = text.replace(/INSERT\s+OR\s+REPLACE\s+INTO\s+autonomy_outcomes\s*\(([^)]+)\)\s*VALUES\s*\(([^)]+)\)/i,
|
||||||
(match, columns, values) => {
|
(match, columns, values) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user