pg-to-sqlite 0.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/pg-sqlite-compiler/catalog/seed.d.ts +67 -0
- package/dist/pg-sqlite-compiler/catalog/seed.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/catalog/seed.js +436 -0
- package/dist/pg-sqlite-compiler/catalog/seed.js.map +1 -0
- package/dist/pg-sqlite-compiler/index.d.ts +17 -0
- package/dist/pg-sqlite-compiler/index.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/index.js +82 -0
- package/dist/pg-sqlite-compiler/index.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/ast-utils.d.ts +48 -0
- package/dist/pg-sqlite-compiler/passes/ast-utils.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/ast-utils.js +93 -0
- package/dist/pg-sqlite-compiler/passes/ast-utils.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/catalog.d.ts +34 -0
- package/dist/pg-sqlite-compiler/passes/catalog.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/catalog.js +30 -0
- package/dist/pg-sqlite-compiler/passes/catalog.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/datetime.d.ts +21 -0
- package/dist/pg-sqlite-compiler/passes/datetime.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/datetime.js +53 -0
- package/dist/pg-sqlite-compiler/passes/datetime.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/index.d.ts +21 -0
- package/dist/pg-sqlite-compiler/passes/index.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/index.js +39 -0
- package/dist/pg-sqlite-compiler/passes/index.js.map +1 -0
- package/dist/pg-sqlite-compiler/passes/types.d.ts +41 -0
- package/dist/pg-sqlite-compiler/passes/types.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/passes/types.js +103 -0
- package/dist/pg-sqlite-compiler/passes/types.js.map +1 -0
- package/dist/pg-sqlite-compiler/types.d.ts +57 -0
- package/dist/pg-sqlite-compiler/types.d.ts.map +1 -0
- package/dist/pg-sqlite-compiler/types.js +2 -0
- package/dist/pg-sqlite-compiler/types.js.map +1 -0
- package/dist/sqlite-keyword-identifiers.d.ts +3 -0
- package/dist/sqlite-keyword-identifiers.d.ts.map +1 -0
- package/dist/sqlite-keyword-identifiers.js +233 -0
- package/dist/sqlite-keyword-identifiers.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
const SQLITE_RESERVED_KEYWORDS = new Set([
|
|
2
|
+
'abort',
|
|
3
|
+
'action',
|
|
4
|
+
'add',
|
|
5
|
+
'after',
|
|
6
|
+
'all',
|
|
7
|
+
'alter',
|
|
8
|
+
'always',
|
|
9
|
+
'analyze',
|
|
10
|
+
'and',
|
|
11
|
+
'as',
|
|
12
|
+
'asc',
|
|
13
|
+
'attach',
|
|
14
|
+
'autoincrement',
|
|
15
|
+
'before',
|
|
16
|
+
'begin',
|
|
17
|
+
'between',
|
|
18
|
+
'by',
|
|
19
|
+
'cascade',
|
|
20
|
+
'case',
|
|
21
|
+
'cast',
|
|
22
|
+
'check',
|
|
23
|
+
'collate',
|
|
24
|
+
'column',
|
|
25
|
+
'commit',
|
|
26
|
+
'conflict',
|
|
27
|
+
'constraint',
|
|
28
|
+
'create',
|
|
29
|
+
'cross',
|
|
30
|
+
'current',
|
|
31
|
+
'current_date',
|
|
32
|
+
'current_time',
|
|
33
|
+
'current_timestamp',
|
|
34
|
+
'database',
|
|
35
|
+
'default',
|
|
36
|
+
'deferrable',
|
|
37
|
+
'deferred',
|
|
38
|
+
'delete',
|
|
39
|
+
'desc',
|
|
40
|
+
'detach',
|
|
41
|
+
'distinct',
|
|
42
|
+
'do',
|
|
43
|
+
'drop',
|
|
44
|
+
'each',
|
|
45
|
+
'else',
|
|
46
|
+
'end',
|
|
47
|
+
'escape',
|
|
48
|
+
'except',
|
|
49
|
+
'exclude',
|
|
50
|
+
'exclusive',
|
|
51
|
+
'exists',
|
|
52
|
+
'explain',
|
|
53
|
+
'fail',
|
|
54
|
+
'filter',
|
|
55
|
+
'first',
|
|
56
|
+
'following',
|
|
57
|
+
'for',
|
|
58
|
+
'foreign',
|
|
59
|
+
'from',
|
|
60
|
+
'full',
|
|
61
|
+
'generated',
|
|
62
|
+
'glob',
|
|
63
|
+
'group',
|
|
64
|
+
'groups',
|
|
65
|
+
'having',
|
|
66
|
+
'if',
|
|
67
|
+
'ignore',
|
|
68
|
+
'immediate',
|
|
69
|
+
'in',
|
|
70
|
+
'index',
|
|
71
|
+
'indexed',
|
|
72
|
+
'initially',
|
|
73
|
+
'inner',
|
|
74
|
+
'insert',
|
|
75
|
+
'instead',
|
|
76
|
+
'intersect',
|
|
77
|
+
'into',
|
|
78
|
+
'is',
|
|
79
|
+
'isnull',
|
|
80
|
+
'join',
|
|
81
|
+
'key',
|
|
82
|
+
'last',
|
|
83
|
+
'left',
|
|
84
|
+
'like',
|
|
85
|
+
'limit',
|
|
86
|
+
'match',
|
|
87
|
+
'materialized',
|
|
88
|
+
'natural',
|
|
89
|
+
'no',
|
|
90
|
+
'not',
|
|
91
|
+
'nothing',
|
|
92
|
+
'notnull',
|
|
93
|
+
'null',
|
|
94
|
+
'nulls',
|
|
95
|
+
'of',
|
|
96
|
+
'offset',
|
|
97
|
+
'on',
|
|
98
|
+
'or',
|
|
99
|
+
'order',
|
|
100
|
+
'others',
|
|
101
|
+
'outer',
|
|
102
|
+
'over',
|
|
103
|
+
'partition',
|
|
104
|
+
'plan',
|
|
105
|
+
'pragma',
|
|
106
|
+
'preceding',
|
|
107
|
+
'primary',
|
|
108
|
+
'query',
|
|
109
|
+
'raise',
|
|
110
|
+
'range',
|
|
111
|
+
'recursive',
|
|
112
|
+
'references',
|
|
113
|
+
'regexp',
|
|
114
|
+
'reindex',
|
|
115
|
+
'release',
|
|
116
|
+
'rename',
|
|
117
|
+
'replace',
|
|
118
|
+
'restrict',
|
|
119
|
+
'returning',
|
|
120
|
+
'right',
|
|
121
|
+
'rollback',
|
|
122
|
+
'row',
|
|
123
|
+
'rows',
|
|
124
|
+
'savepoint',
|
|
125
|
+
'select',
|
|
126
|
+
'set',
|
|
127
|
+
'table',
|
|
128
|
+
'temp',
|
|
129
|
+
'temporary',
|
|
130
|
+
'then',
|
|
131
|
+
'ties',
|
|
132
|
+
'to',
|
|
133
|
+
'transaction',
|
|
134
|
+
'trigger',
|
|
135
|
+
'unbounded',
|
|
136
|
+
'union',
|
|
137
|
+
'unique',
|
|
138
|
+
'update',
|
|
139
|
+
'using',
|
|
140
|
+
'vacuum',
|
|
141
|
+
'values',
|
|
142
|
+
'view',
|
|
143
|
+
'virtual',
|
|
144
|
+
'when',
|
|
145
|
+
'where',
|
|
146
|
+
'window',
|
|
147
|
+
'with',
|
|
148
|
+
'without',
|
|
149
|
+
]);
|
|
150
|
+
const IDENTIFIER_KEYS = new Set([
|
|
151
|
+
'aliasname',
|
|
152
|
+
'catalogname',
|
|
153
|
+
'colname',
|
|
154
|
+
'conname',
|
|
155
|
+
'dbname',
|
|
156
|
+
'fdwname',
|
|
157
|
+
'idxname',
|
|
158
|
+
'indexname',
|
|
159
|
+
'name',
|
|
160
|
+
'newname',
|
|
161
|
+
'plname',
|
|
162
|
+
'portalname',
|
|
163
|
+
'provider',
|
|
164
|
+
'relname',
|
|
165
|
+
'rolename',
|
|
166
|
+
'rulename',
|
|
167
|
+
'schemaname',
|
|
168
|
+
'servername',
|
|
169
|
+
'subname',
|
|
170
|
+
'tableSpaceName',
|
|
171
|
+
'trigname',
|
|
172
|
+
]);
|
|
173
|
+
const MARKER_PREFIX = '__orez_sqlite_quote_marker_';
|
|
174
|
+
const MARKER_SUFFIX = '__X';
|
|
175
|
+
function quoteIdentifier(value) {
|
|
176
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
177
|
+
}
|
|
178
|
+
function needsSQLiteKeywordQuote(value) {
|
|
179
|
+
return SQLITE_RESERVED_KEYWORDS.has(value.toLowerCase());
|
|
180
|
+
}
|
|
181
|
+
export function markSQLiteKeywordIdentifiers(root) {
|
|
182
|
+
const markers = new Map();
|
|
183
|
+
const quotedByMarker = new Map();
|
|
184
|
+
let markerIndex = 0;
|
|
185
|
+
const markerFor = (value) => {
|
|
186
|
+
const existing = markers.get(value);
|
|
187
|
+
if (existing)
|
|
188
|
+
return existing;
|
|
189
|
+
const marker = `${MARKER_PREFIX}${markerIndex++}${MARKER_SUFFIX}`;
|
|
190
|
+
markers.set(value, marker);
|
|
191
|
+
quotedByMarker.set(marker, quoteIdentifier(value));
|
|
192
|
+
return marker;
|
|
193
|
+
};
|
|
194
|
+
const visit = (node, inColumnRef = false) => {
|
|
195
|
+
if (!node || typeof node !== 'object')
|
|
196
|
+
return;
|
|
197
|
+
if (Array.isArray(node)) {
|
|
198
|
+
for (const item of node)
|
|
199
|
+
visit(item, inColumnRef);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const record = node;
|
|
203
|
+
const childColumnRef = inColumnRef || typeof record.ColumnRef === 'object';
|
|
204
|
+
for (const [key, value] of Object.entries(record)) {
|
|
205
|
+
if (IDENTIFIER_KEYS.has(key) &&
|
|
206
|
+
typeof value === 'string' &&
|
|
207
|
+
needsSQLiteKeywordQuote(value)) {
|
|
208
|
+
record[key] = markerFor(value);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (childColumnRef &&
|
|
212
|
+
key === 'sval' &&
|
|
213
|
+
typeof value === 'string' &&
|
|
214
|
+
needsSQLiteKeywordQuote(value)) {
|
|
215
|
+
record[key] = markerFor(value);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
visit(value, childColumnRef);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
visit(root);
|
|
222
|
+
return quotedByMarker;
|
|
223
|
+
}
|
|
224
|
+
export function restoreSQLiteKeywordIdentifierMarkers(sql, quotedByMarker) {
|
|
225
|
+
let next = sql;
|
|
226
|
+
for (const [marker, quotedIdentifier] of quotedByMarker) {
|
|
227
|
+
next = next
|
|
228
|
+
.replaceAll(quoteIdentifier(marker), quotedIdentifier)
|
|
229
|
+
.replaceAll(marker, quotedIdentifier);
|
|
230
|
+
}
|
|
231
|
+
return next;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=sqlite-keyword-identifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-keyword-identifiers.js","sourceRoot":"","sources":["../src/sqlite-keyword-identifiers.ts"],"names":[],"mappings":"AAAA,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACvC,OAAO;IACP,QAAQ;IACR,KAAK;IACL,OAAO;IACP,KAAK;IACL,OAAO;IACP,QAAQ;IACR,SAAS;IACT,KAAK;IACL,IAAI;IACJ,KAAK;IACL,QAAQ;IACR,eAAe;IACf,QAAQ;IACR,OAAO;IACP,SAAS;IACT,IAAI;IACJ,SAAS;IACT,MAAM;IACN,MAAM;IACN,OAAO;IACP,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,OAAO;IACP,SAAS;IACT,cAAc;IACd,cAAc;IACd,mBAAmB;IACnB,UAAU;IACV,SAAS;IACT,YAAY;IACZ,UAAU;IACV,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,UAAU;IACV,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,WAAW;IACX,QAAQ;IACR,SAAS;IACT,MAAM;IACN,QAAQ;IACR,OAAO;IACP,WAAW;IACX,KAAK;IACL,SAAS;IACT,MAAM;IACN,MAAM;IACN,WAAW;IACX,MAAM;IACN,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,IAAI;IACJ,QAAQ;IACR,WAAW;IACX,IAAI;IACJ,OAAO;IACP,SAAS;IACT,WAAW;IACX,OAAO;IACP,QAAQ;IACR,S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AA;QAE1E,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,IACE,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC;gBACxB,OAAO,KAAK,KAAK,QAAQ;gBACzB,uBAAuB,CAAC,KAAK,CAAC,EAC9B,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;gBAC9B,SAAQ;YACV,CAAC;YAED,IACE,cAAc;gBACd,GAAG,KAAK,MAAM;gBACd,OAAO,KAAK,KAAK,QAAQ;gBACzB,uBAAuB,CAAC,KAAK,CAAC,EAC9B,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;gBAC9B,SAAQ;YACV,CAAC;YAED,KAAK,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;QAC9B,CAAC;IACH,CAAC,CAAA;IAED,KAAK,CAAC,IAAI,CAAC,CAAA;IACX,OAAO,cAAc,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,qCAAqC,CACnD,GAAW,EACX,cAAmC;IAEnC,IAAI,IAAI,GAAG,GAAG,CAAA;IACd,KAAK,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAAI,cAAc,EAAE,CAAC;QACxD,IAAI,GAAG,IAAI;aACR,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;aACrD,UAAU,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IACzC,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pg-to-sqlite",
|
|
3
|
+
"version": "0.4.16",
|
|
4
|
+
"description": "PostgreSQL SQL to SQLite SQL compiler.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/pg-sqlite-compiler/index.js",
|
|
8
|
+
"types": "dist/pg-sqlite-compiler/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/pg-sqlite-compiler/index.d.ts",
|
|
12
|
+
"import": "./dist/pg-sqlite-compiler/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"pgsql-parser": "^17.9.11"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/natew/orez.git",
|
|
24
|
+
"directory": "pg-to-sqlite"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"postgres",
|
|
28
|
+
"postgresql",
|
|
29
|
+
"sqlite",
|
|
30
|
+
"sql",
|
|
31
|
+
"compiler",
|
|
32
|
+
"cloudflare"
|
|
33
|
+
]
|
|
34
|
+
}
|