drizzle-kit 0.20.5-c7dc2fe → 0.20.5-fd4dd75
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/bin.cjs +4052 -2001
- package/cli/commands/pgIntrospect.d.ts +6 -1
- package/cli/commands/sqliteIntrospect.d.ts +6 -1
- package/cli/commands/utils.d.ts +1 -1
- package/cli/utils.d.ts +1 -0
- package/introspect-pg.d.ts +12 -0
- package/introspect-sqlite.d.ts +10 -0
- package/package.json +7 -6
- package/serializer/studioUtils.d.ts +15 -3
- package/utils-studio.js +1288 -1285
- package/utils-studio.mjs +1337 -1329
- package/utils.js +3645 -1771
- package/introspect.d.ts +0 -4
- package/sqlite-introspect.d.ts +0 -5
package/utils-studio.js
CHANGED
|
@@ -542,1358 +542,1359 @@ var init_source = __esm({
|
|
|
542
542
|
}
|
|
543
543
|
});
|
|
544
544
|
|
|
545
|
-
//
|
|
546
|
-
var
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
545
|
+
// node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js
|
|
546
|
+
var require_readline = __commonJS({
|
|
547
|
+
"node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js"(exports) {
|
|
548
|
+
"use strict";
|
|
549
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
550
|
+
exports.prepareReadLine = void 0;
|
|
551
|
+
var prepareReadLine = () => {
|
|
552
|
+
const stdin = process.stdin;
|
|
553
|
+
const stdout = process.stdout;
|
|
554
|
+
const readline = require("readline");
|
|
555
|
+
const rl = readline.createInterface({
|
|
556
|
+
input: stdin,
|
|
557
|
+
escapeCodeTimeout: 50
|
|
558
|
+
});
|
|
559
|
+
readline.emitKeypressEvents(stdin, rl);
|
|
560
|
+
return {
|
|
561
|
+
stdin,
|
|
562
|
+
stdout,
|
|
563
|
+
closable: rl
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
exports.prepareReadLine = prepareReadLine;
|
|
551
567
|
}
|
|
552
568
|
});
|
|
553
569
|
|
|
554
|
-
//
|
|
555
|
-
var
|
|
556
|
-
"
|
|
557
|
-
|
|
570
|
+
// node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
571
|
+
var require_src = __commonJS({
|
|
572
|
+
"node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module2) {
|
|
573
|
+
"use strict";
|
|
574
|
+
var ESC = "\x1B";
|
|
575
|
+
var CSI = `${ESC}[`;
|
|
576
|
+
var beep = "\x07";
|
|
577
|
+
var cursor = {
|
|
578
|
+
to(x, y) {
|
|
579
|
+
if (!y)
|
|
580
|
+
return `${CSI}${x + 1}G`;
|
|
581
|
+
return `${CSI}${y + 1};${x + 1}H`;
|
|
582
|
+
},
|
|
583
|
+
move(x, y) {
|
|
584
|
+
let ret = "";
|
|
585
|
+
if (x < 0)
|
|
586
|
+
ret += `${CSI}${-x}D`;
|
|
587
|
+
else if (x > 0)
|
|
588
|
+
ret += `${CSI}${x}C`;
|
|
589
|
+
if (y < 0)
|
|
590
|
+
ret += `${CSI}${-y}A`;
|
|
591
|
+
else if (y > 0)
|
|
592
|
+
ret += `${CSI}${y}B`;
|
|
593
|
+
return ret;
|
|
594
|
+
},
|
|
595
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
596
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
597
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
598
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
599
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
600
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
601
|
+
left: `${CSI}G`,
|
|
602
|
+
hide: `${CSI}?25l`,
|
|
603
|
+
show: `${CSI}?25h`,
|
|
604
|
+
save: `${ESC}7`,
|
|
605
|
+
restore: `${ESC}8`
|
|
606
|
+
};
|
|
607
|
+
var scroll = {
|
|
608
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
609
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
610
|
+
};
|
|
611
|
+
var erase = {
|
|
612
|
+
screen: `${CSI}2J`,
|
|
613
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
614
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
615
|
+
line: `${CSI}2K`,
|
|
616
|
+
lineEnd: `${CSI}K`,
|
|
617
|
+
lineStart: `${CSI}1K`,
|
|
618
|
+
lines(count) {
|
|
619
|
+
let clear = "";
|
|
620
|
+
for (let i = 0; i < count; i++)
|
|
621
|
+
clear += this.line + (i < count - 1 ? cursor.up() : "");
|
|
622
|
+
if (count)
|
|
623
|
+
clear += cursor.left;
|
|
624
|
+
return clear;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
module2.exports = { cursor, scroll, erase, beep };
|
|
558
628
|
}
|
|
559
629
|
});
|
|
560
630
|
|
|
561
|
-
//
|
|
562
|
-
var
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
while (start < end && str[start] === char)
|
|
576
|
-
++start;
|
|
577
|
-
while (end > start && str[end - 1] === char)
|
|
578
|
-
--end;
|
|
579
|
-
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
|
631
|
+
// node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js
|
|
632
|
+
var require_utils = __commonJS({
|
|
633
|
+
"node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js"(exports) {
|
|
634
|
+
"use strict";
|
|
635
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
636
|
+
exports.clear = void 0;
|
|
637
|
+
var sisteransi_1 = require_src();
|
|
638
|
+
var strip = (str) => {
|
|
639
|
+
const pattern = [
|
|
640
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
641
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
|
|
642
|
+
].join("|");
|
|
643
|
+
const RGX = new RegExp(pattern, "g");
|
|
644
|
+
return typeof str === "string" ? str.replace(RGX, "") : str;
|
|
580
645
|
};
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
)
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
646
|
+
var stringWidth = (str) => [...strip(str)].length;
|
|
647
|
+
var clear = function(prompt, perLine) {
|
|
648
|
+
if (!perLine)
|
|
649
|
+
return sisteransi_1.erase.line + sisteransi_1.cursor.to(0);
|
|
650
|
+
let rows = 0;
|
|
651
|
+
const lines = prompt.split(/\r?\n/);
|
|
652
|
+
for (let line of lines) {
|
|
653
|
+
rows += 1 + Math.floor(Math.max(stringWidth(line) - 1, 0) / perLine);
|
|
654
|
+
}
|
|
655
|
+
return sisteransi_1.erase.lines(rows);
|
|
656
|
+
};
|
|
657
|
+
exports.clear = clear;
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
// node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js
|
|
662
|
+
var require_lodash = __commonJS({
|
|
663
|
+
"node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js"(exports, module2) {
|
|
664
|
+
var FUNC_ERROR_TEXT = "Expected a function";
|
|
665
|
+
var NAN = 0 / 0;
|
|
666
|
+
var symbolTag = "[object Symbol]";
|
|
667
|
+
var reTrim = /^\s+|\s+$/g;
|
|
668
|
+
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
|
669
|
+
var reIsBinary = /^0b[01]+$/i;
|
|
670
|
+
var reIsOctal = /^0o[0-7]+$/i;
|
|
671
|
+
var freeParseInt = parseInt;
|
|
672
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
673
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
674
|
+
var root = freeGlobal || freeSelf || Function("return this")();
|
|
675
|
+
var objectProto = Object.prototype;
|
|
676
|
+
var objectToString = objectProto.toString;
|
|
677
|
+
var nativeMax = Math.max;
|
|
678
|
+
var nativeMin = Math.min;
|
|
679
|
+
var now = function() {
|
|
680
|
+
return root.Date.now();
|
|
681
|
+
};
|
|
682
|
+
function debounce(func, wait, options) {
|
|
683
|
+
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
|
|
684
|
+
if (typeof func != "function") {
|
|
685
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
686
|
+
}
|
|
687
|
+
wait = toNumber(wait) || 0;
|
|
688
|
+
if (isObject(options)) {
|
|
689
|
+
leading = !!options.leading;
|
|
690
|
+
maxing = "maxWait" in options;
|
|
691
|
+
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
|
|
692
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
693
|
+
}
|
|
694
|
+
function invokeFunc(time) {
|
|
695
|
+
var args = lastArgs, thisArg = lastThis;
|
|
696
|
+
lastArgs = lastThis = void 0;
|
|
697
|
+
lastInvokeTime = time;
|
|
698
|
+
result = func.apply(thisArg, args);
|
|
699
|
+
return result;
|
|
700
|
+
}
|
|
701
|
+
function leadingEdge(time) {
|
|
702
|
+
lastInvokeTime = time;
|
|
703
|
+
timerId = setTimeout(timerExpired, wait);
|
|
704
|
+
return leading ? invokeFunc(time) : result;
|
|
705
|
+
}
|
|
706
|
+
function remainingWait(time) {
|
|
707
|
+
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, result2 = wait - timeSinceLastCall;
|
|
708
|
+
return maxing ? nativeMin(result2, maxWait - timeSinceLastInvoke) : result2;
|
|
709
|
+
}
|
|
710
|
+
function shouldInvoke(time) {
|
|
711
|
+
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
|
|
712
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
713
|
+
}
|
|
714
|
+
function timerExpired() {
|
|
715
|
+
var time = now();
|
|
716
|
+
if (shouldInvoke(time)) {
|
|
717
|
+
return trailingEdge(time);
|
|
600
718
|
}
|
|
601
|
-
|
|
602
|
-
let columnsCount = 0;
|
|
603
|
-
let indexesCount = 0;
|
|
604
|
-
let foreignKeysCount = 0;
|
|
605
|
-
let tableCount = 0;
|
|
606
|
-
const all = allTables.map((row) => {
|
|
607
|
-
return new Promise(async (res, rej) => {
|
|
608
|
-
const tableName = row.table_name;
|
|
609
|
-
if (!tablesFilter(tableName))
|
|
610
|
-
return res("");
|
|
611
|
-
tableCount += 1;
|
|
612
|
-
const tableSchema = row.table_schema;
|
|
613
|
-
try {
|
|
614
|
-
const columnToReturn = {};
|
|
615
|
-
const indexToReturn = {};
|
|
616
|
-
const foreignKeysToReturn = {};
|
|
617
|
-
const primaryKeys = {};
|
|
618
|
-
const uniqueConstrains = {};
|
|
619
|
-
const tableResponse = await db.query(
|
|
620
|
-
`SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
|
|
621
|
-
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
|
622
|
-
AND EXISTS (
|
|
623
|
-
SELECT FROM pg_attrdef ad
|
|
624
|
-
WHERE ad.adrelid = a.attrelid
|
|
625
|
-
AND ad.adnum = a.attnum
|
|
626
|
-
AND pg_get_expr(ad.adbin, ad.adrelid)
|
|
627
|
-
= 'nextval('''
|
|
628
|
-
|| (pg_get_serial_sequence (a.attrelid::regclass::text
|
|
629
|
-
, a.attname))::regclass
|
|
630
|
-
|| '''::regclass)'
|
|
631
|
-
)
|
|
632
|
-
THEN CASE a.atttypid
|
|
633
|
-
WHEN 'int'::regtype THEN 'serial'
|
|
634
|
-
WHEN 'int8'::regtype THEN 'bigserial'
|
|
635
|
-
WHEN 'int2'::regtype THEN 'smallserial'
|
|
636
|
-
END
|
|
637
|
-
ELSE format_type(a.atttypid, a.atttypmod)
|
|
638
|
-
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, INFORMATION_SCHEMA.COLUMNS.column_name, INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt
|
|
639
|
-
FROM pg_attribute a
|
|
640
|
-
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
|
641
|
-
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}'
|
|
642
|
-
AND a.attnum > 0
|
|
643
|
-
AND NOT a.attisdropped
|
|
644
|
-
ORDER BY a.attnum;`
|
|
645
|
-
);
|
|
646
|
-
const tableConstraints = await db.query(
|
|
647
|
-
`SELECT c.column_name, c.data_type, constraint_type, constraint_name, constraint_schema
|
|
648
|
-
FROM information_schema.table_constraints tc
|
|
649
|
-
JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
|
|
650
|
-
JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema
|
|
651
|
-
AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
|
|
652
|
-
WHERE tc.table_name = '${tableName}' and constraint_schema = '${tableSchema}';`
|
|
653
|
-
);
|
|
654
|
-
columnsCount += tableResponse.length;
|
|
655
|
-
if (progressCallback) {
|
|
656
|
-
progressCallback("columns", columnsCount, "fetching");
|
|
657
|
-
}
|
|
658
|
-
const tableForeignKeys = await db.query(
|
|
659
|
-
`SELECT
|
|
660
|
-
tc.table_schema,
|
|
661
|
-
tc.constraint_name,
|
|
662
|
-
tc.table_name,
|
|
663
|
-
kcu.column_name,
|
|
664
|
-
ccu.table_schema AS foreign_table_schema,
|
|
665
|
-
ccu.table_name AS foreign_table_name,
|
|
666
|
-
ccu.column_name AS foreign_column_name,
|
|
667
|
-
rc.delete_rule, rc.update_rule
|
|
668
|
-
FROM
|
|
669
|
-
information_schema.table_constraints AS tc
|
|
670
|
-
JOIN information_schema.key_column_usage AS kcu
|
|
671
|
-
ON tc.constraint_name = kcu.constraint_name
|
|
672
|
-
AND tc.table_schema = kcu.table_schema
|
|
673
|
-
JOIN information_schema.constraint_column_usage AS ccu
|
|
674
|
-
ON ccu.constraint_name = tc.constraint_name
|
|
675
|
-
AND ccu.table_schema = tc.table_schema
|
|
676
|
-
JOIN information_schema.referential_constraints AS rc
|
|
677
|
-
ON ccu.constraint_name = rc.constraint_name
|
|
678
|
-
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
|
|
679
|
-
);
|
|
680
|
-
foreignKeysCount += tableForeignKeys.length;
|
|
681
|
-
if (progressCallback) {
|
|
682
|
-
progressCallback("fks", foreignKeysCount, "fetching");
|
|
683
|
-
}
|
|
684
|
-
for (const fk of tableForeignKeys) {
|
|
685
|
-
const columnFrom = fk.column_name;
|
|
686
|
-
const tableTo = fk.foreign_table_name;
|
|
687
|
-
const columnTo = fk.foreign_column_name;
|
|
688
|
-
const foreignKeyName = fk.constraint_name;
|
|
689
|
-
const onUpdate = fk.update_rule.toLowerCase();
|
|
690
|
-
const onDelete = fk.delete_rule.toLowerCase();
|
|
691
|
-
if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
|
|
692
|
-
foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
|
|
693
|
-
foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
|
|
694
|
-
} else {
|
|
695
|
-
foreignKeysToReturn[foreignKeyName] = {
|
|
696
|
-
name: foreignKeyName,
|
|
697
|
-
tableFrom: tableName,
|
|
698
|
-
tableTo,
|
|
699
|
-
columnsFrom: [columnFrom],
|
|
700
|
-
columnsTo: [columnTo],
|
|
701
|
-
onDelete,
|
|
702
|
-
onUpdate
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
foreignKeysToReturn[foreignKeyName].columnsFrom = [
|
|
706
|
-
...new Set(foreignKeysToReturn[foreignKeyName].columnsFrom)
|
|
707
|
-
];
|
|
708
|
-
foreignKeysToReturn[foreignKeyName].columnsTo = [
|
|
709
|
-
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
|
710
|
-
];
|
|
711
|
-
}
|
|
712
|
-
const uniqueConstrainsRows = tableConstraints.filter(
|
|
713
|
-
(mapRow) => mapRow.constraint_type === "UNIQUE"
|
|
714
|
-
);
|
|
715
|
-
for (const unqs of uniqueConstrainsRows) {
|
|
716
|
-
const columnName = unqs.column_name;
|
|
717
|
-
const constraintName = unqs.constraint_name;
|
|
718
|
-
if (typeof uniqueConstrains[constraintName] !== "undefined") {
|
|
719
|
-
uniqueConstrains[constraintName].columns.push(columnName);
|
|
720
|
-
} else {
|
|
721
|
-
uniqueConstrains[constraintName] = {
|
|
722
|
-
columns: [columnName],
|
|
723
|
-
nullsNotDistinct: false,
|
|
724
|
-
name: constraintName
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
for (const columnResponse of tableResponse) {
|
|
729
|
-
const columnName = columnResponse.attname;
|
|
730
|
-
const columnAdditionalDT = columnResponse.additional_dt;
|
|
731
|
-
const columnDimensions = columnResponse.array_dimensions;
|
|
732
|
-
let columnType = columnResponse.data_type;
|
|
733
|
-
const primaryKey = tableConstraints.filter(
|
|
734
|
-
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
|
|
735
|
-
);
|
|
736
|
-
const cprimaryKey = tableConstraints.filter(
|
|
737
|
-
(mapRow) => mapRow.constraint_type === "PRIMARY KEY"
|
|
738
|
-
);
|
|
739
|
-
if (cprimaryKey.length > 1) {
|
|
740
|
-
const tableCompositePkName = await db.query(
|
|
741
|
-
`SELECT conname AS primary_key
|
|
742
|
-
FROM pg_constraint join pg_class on (pg_class.oid = conrelid)
|
|
743
|
-
WHERE contype = 'p'
|
|
744
|
-
AND connamespace = $1::regnamespace
|
|
745
|
-
AND pg_class.relname = $2;`,
|
|
746
|
-
[tableSchema, tableName]
|
|
747
|
-
);
|
|
748
|
-
primaryKeys[tableCompositePkName[0].primary_key] = {
|
|
749
|
-
name: tableCompositePkName[0].primary_key,
|
|
750
|
-
columns: cprimaryKey.map((c) => c.column_name)
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
const defaultValue = defaultForColumn(columnResponse);
|
|
754
|
-
const isSerial = columnType === "serial";
|
|
755
|
-
let columnTypeMapped = columnType;
|
|
756
|
-
if (columnTypeMapped.startsWith("numeric(")) {
|
|
757
|
-
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
|
758
|
-
}
|
|
759
|
-
if (columnAdditionalDT === "ARRAY") {
|
|
760
|
-
if (typeof internals.tables[tableName] === "undefined") {
|
|
761
|
-
internals.tables[tableName] = {
|
|
762
|
-
columns: {
|
|
763
|
-
[columnName]: {
|
|
764
|
-
isArray: true,
|
|
765
|
-
dimensions: columnDimensions,
|
|
766
|
-
rawType: columnTypeMapped.substring(
|
|
767
|
-
0,
|
|
768
|
-
columnTypeMapped.length - 2
|
|
769
|
-
)
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
} else {
|
|
774
|
-
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
|
775
|
-
internals.tables[tableName].columns[columnName] = {
|
|
776
|
-
isArray: true,
|
|
777
|
-
dimensions: columnDimensions,
|
|
778
|
-
rawType: columnTypeMapped.substring(
|
|
779
|
-
0,
|
|
780
|
-
columnTypeMapped.length - 2
|
|
781
|
-
)
|
|
782
|
-
};
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
if (columnAdditionalDT === "ARRAY") {
|
|
787
|
-
for (let i = 1; i < Number(columnDimensions); i++) {
|
|
788
|
-
columnTypeMapped += "[]";
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
|
|
792
|
-
columnTypeMapped = trimChar(columnTypeMapped, '"');
|
|
793
|
-
columnToReturn[columnName] = {
|
|
794
|
-
name: columnName,
|
|
795
|
-
type: columnTypeMapped,
|
|
796
|
-
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
|
797
|
-
// default: isSerial ? undefined : defaultValue,
|
|
798
|
-
notNull: columnResponse.is_nullable === "NO"
|
|
799
|
-
};
|
|
800
|
-
if (!isSerial && typeof defaultValue !== "undefined") {
|
|
801
|
-
columnToReturn[columnName].default = defaultValue;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
const dbIndexes = await db.query(
|
|
805
|
-
`SELECT t.relname as table_name, i.relname AS index_name, ix.indisunique AS is_unique, a.attname AS column_name
|
|
806
|
-
FROM pg_class t
|
|
807
|
-
JOIN pg_index ix ON t.oid = ix.indrelid
|
|
808
|
-
JOIN pg_class i ON i.oid = ix.indexrelid
|
|
809
|
-
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
|
|
810
|
-
JOIN pg_namespace ns ON ns.oid = t.relnamespace
|
|
811
|
-
WHERE ns.nspname = '${tableSchema}'
|
|
812
|
-
AND t.relname = '${tableName}'
|
|
813
|
-
and ix.indisprimary = false;`
|
|
814
|
-
);
|
|
815
|
-
const dbIndexFromConstraint = await db.query(
|
|
816
|
-
`SELECT
|
|
817
|
-
idx.indexrelname AS index_name,
|
|
818
|
-
idx.relname AS table_name,
|
|
819
|
-
schemaname,
|
|
820
|
-
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
|
|
821
|
-
FROM
|
|
822
|
-
pg_stat_user_indexes idx
|
|
823
|
-
LEFT JOIN
|
|
824
|
-
pg_constraint con ON con.conindid = idx.indexrelid
|
|
825
|
-
WHERE idx.relname = '${tableName}' and schemaname = '${tableSchema}'
|
|
826
|
-
group by index_name, table_name,schemaname, generated_by_constraint;`
|
|
827
|
-
);
|
|
828
|
-
const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
|
|
829
|
-
for (const dbIndex of dbIndexes) {
|
|
830
|
-
const indexName2 = dbIndex.index_name;
|
|
831
|
-
const indexColumnName = dbIndex.column_name;
|
|
832
|
-
const indexIsUnique = dbIndex.is_unique;
|
|
833
|
-
if (idxsInConsteraint.includes(indexName2))
|
|
834
|
-
continue;
|
|
835
|
-
if (typeof indexToReturn[indexName2] !== "undefined") {
|
|
836
|
-
indexToReturn[indexName2].columns.push(indexColumnName);
|
|
837
|
-
} else {
|
|
838
|
-
indexToReturn[indexName2] = {
|
|
839
|
-
name: indexName2,
|
|
840
|
-
columns: [indexColumnName],
|
|
841
|
-
isUnique: indexIsUnique
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
indexesCount += Object.keys(indexToReturn).length;
|
|
846
|
-
if (progressCallback) {
|
|
847
|
-
progressCallback("indexes", indexesCount, "fetching");
|
|
848
|
-
}
|
|
849
|
-
result[tableName] = {
|
|
850
|
-
name: tableName,
|
|
851
|
-
schema: tableSchema !== "public" ? tableSchema : "",
|
|
852
|
-
columns: columnToReturn,
|
|
853
|
-
indexes: indexToReturn,
|
|
854
|
-
foreignKeys: foreignKeysToReturn,
|
|
855
|
-
compositePrimaryKeys: primaryKeys,
|
|
856
|
-
uniqueConstraints: uniqueConstrains
|
|
857
|
-
};
|
|
858
|
-
} catch (e) {
|
|
859
|
-
rej(e);
|
|
860
|
-
return;
|
|
861
|
-
}
|
|
862
|
-
res("");
|
|
863
|
-
});
|
|
864
|
-
});
|
|
865
|
-
if (progressCallback) {
|
|
866
|
-
progressCallback("tables", tableCount, "done");
|
|
719
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
867
720
|
}
|
|
868
|
-
|
|
721
|
+
function trailingEdge(time) {
|
|
722
|
+
timerId = void 0;
|
|
723
|
+
if (trailing && lastArgs) {
|
|
724
|
+
return invokeFunc(time);
|
|
725
|
+
}
|
|
726
|
+
lastArgs = lastThis = void 0;
|
|
727
|
+
return result;
|
|
869
728
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
729
|
+
function cancel() {
|
|
730
|
+
if (timerId !== void 0) {
|
|
731
|
+
clearTimeout(timerId);
|
|
732
|
+
}
|
|
733
|
+
lastInvokeTime = 0;
|
|
734
|
+
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
874
735
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
736
|
+
function flush() {
|
|
737
|
+
return timerId === void 0 ? result : trailingEdge(now());
|
|
738
|
+
}
|
|
739
|
+
function debounced() {
|
|
740
|
+
var time = now(), isInvoking = shouldInvoke(time);
|
|
741
|
+
lastArgs = arguments;
|
|
742
|
+
lastThis = this;
|
|
743
|
+
lastCallTime = time;
|
|
744
|
+
if (isInvoking) {
|
|
745
|
+
if (timerId === void 0) {
|
|
746
|
+
return leadingEdge(lastCallTime);
|
|
747
|
+
}
|
|
748
|
+
if (maxing) {
|
|
749
|
+
timerId = setTimeout(timerExpired, wait);
|
|
750
|
+
return invokeFunc(lastCallTime);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (timerId === void 0) {
|
|
754
|
+
timerId = setTimeout(timerExpired, wait);
|
|
894
755
|
}
|
|
756
|
+
return result;
|
|
895
757
|
}
|
|
896
|
-
|
|
897
|
-
|
|
758
|
+
debounced.cancel = cancel;
|
|
759
|
+
debounced.flush = flush;
|
|
760
|
+
return debounced;
|
|
761
|
+
}
|
|
762
|
+
function throttle(func, wait, options) {
|
|
763
|
+
var leading = true, trailing = true;
|
|
764
|
+
if (typeof func != "function") {
|
|
765
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
898
766
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
767
|
+
if (isObject(options)) {
|
|
768
|
+
leading = "leading" in options ? !!options.leading : leading;
|
|
769
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
770
|
+
}
|
|
771
|
+
return debounce(func, wait, {
|
|
772
|
+
"leading": leading,
|
|
773
|
+
"maxWait": wait,
|
|
774
|
+
"trailing": trailing
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
function isObject(value) {
|
|
778
|
+
var type = typeof value;
|
|
779
|
+
return !!value && (type == "object" || type == "function");
|
|
780
|
+
}
|
|
781
|
+
function isObjectLike(value) {
|
|
782
|
+
return !!value && typeof value == "object";
|
|
783
|
+
}
|
|
784
|
+
function isSymbol(value) {
|
|
785
|
+
return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
|
|
786
|
+
}
|
|
787
|
+
function toNumber(value) {
|
|
788
|
+
if (typeof value == "number") {
|
|
789
|
+
return value;
|
|
790
|
+
}
|
|
791
|
+
if (isSymbol(value)) {
|
|
792
|
+
return NAN;
|
|
793
|
+
}
|
|
794
|
+
if (isObject(value)) {
|
|
795
|
+
var other = typeof value.valueOf == "function" ? value.valueOf() : value;
|
|
796
|
+
value = isObject(other) ? other + "" : other;
|
|
797
|
+
}
|
|
798
|
+
if (typeof value != "string") {
|
|
799
|
+
return value === 0 ? value : +value;
|
|
800
|
+
}
|
|
801
|
+
value = value.replace(reTrim, "");
|
|
802
|
+
var isBinary = reIsBinary.test(value);
|
|
803
|
+
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
|
|
804
|
+
}
|
|
805
|
+
module2.exports = throttle;
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
// node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js
|
|
810
|
+
var require_hanji = __commonJS({
|
|
811
|
+
"node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js"(exports) {
|
|
812
|
+
"use strict";
|
|
813
|
+
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
814
|
+
function adopt(value) {
|
|
815
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
816
|
+
resolve(value);
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
820
|
+
function fulfilled(value) {
|
|
821
|
+
try {
|
|
822
|
+
step(generator.next(value));
|
|
823
|
+
} catch (e) {
|
|
824
|
+
reject(e);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
function rejected(value) {
|
|
828
|
+
try {
|
|
829
|
+
step(generator["throw"](value));
|
|
830
|
+
} catch (e) {
|
|
831
|
+
reject(e);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
function step(result) {
|
|
835
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
836
|
+
}
|
|
837
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
838
|
+
});
|
|
913
839
|
};
|
|
914
|
-
|
|
915
|
-
"
|
|
916
|
-
// text: "::text",
|
|
917
|
-
// "character varying": "::character varying",
|
|
918
|
-
// "double precision": "::double precision",
|
|
919
|
-
// "time with time zone": "::time with time zone",
|
|
920
|
-
"time without time zone": "::time without time zone",
|
|
921
|
-
// "timestamp with time zone": "::timestamp with time zone",
|
|
922
|
-
"timestamp without time zone": "::timestamp without time zone",
|
|
923
|
-
// date: "::date",
|
|
924
|
-
// interval: "::interval",
|
|
925
|
-
// character: "::bpchar",
|
|
926
|
-
// macaddr8: "::macaddr8",
|
|
927
|
-
// macaddr: "::macaddr",
|
|
928
|
-
// inet: "::inet",
|
|
929
|
-
// cidr: "::cidr",
|
|
930
|
-
// jsonb: "::jsonb",
|
|
931
|
-
// json: "::json",
|
|
932
|
-
"character(": "::bpchar"
|
|
840
|
+
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
841
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
933
842
|
};
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
843
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
844
|
+
exports.onTerminate = exports.renderWithTask = exports.render = exports.TaskTerminal = exports.TaskView = exports.Terminal = exports.deferred = exports.SelectState = exports.Prompt = void 0;
|
|
845
|
+
var readline_1 = require_readline();
|
|
846
|
+
var sisteransi_1 = require_src();
|
|
847
|
+
var utils_1 = require_utils();
|
|
848
|
+
var lodash_throttle_1 = __importDefault(require_lodash());
|
|
849
|
+
var Prompt2 = class {
|
|
850
|
+
constructor() {
|
|
851
|
+
this.attachCallbacks = [];
|
|
852
|
+
this.detachCallbacks = [];
|
|
853
|
+
this.inputCallbacks = [];
|
|
937
854
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
);
|
|
941
|
-
if (column.column_default === null) {
|
|
942
|
-
return void 0;
|
|
855
|
+
requestLayout() {
|
|
856
|
+
this.terminal.requestLayout();
|
|
943
857
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
return Number(rt);
|
|
952
|
-
} else if (column.data_type === "json" || column.data_type === "jsonb") {
|
|
953
|
-
const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
|
|
954
|
-
return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`}`;
|
|
955
|
-
} else if (column.data_type === "boolean") {
|
|
956
|
-
return column.column_default === "true";
|
|
957
|
-
} else {
|
|
958
|
-
return `'${rt}'`;
|
|
858
|
+
on(type, callback) {
|
|
859
|
+
if (type === "attach") {
|
|
860
|
+
this.attachCallbacks.push(callback);
|
|
861
|
+
} else if (type === "detach") {
|
|
862
|
+
this.detachCallbacks.push(callback);
|
|
863
|
+
} else if (type === "input") {
|
|
864
|
+
this.inputCallbacks.push(callback);
|
|
959
865
|
}
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
866
|
+
}
|
|
867
|
+
attach(terminal) {
|
|
868
|
+
this.terminal = terminal;
|
|
869
|
+
this.attachCallbacks.forEach((it) => it(terminal));
|
|
870
|
+
}
|
|
871
|
+
detach(terminal) {
|
|
872
|
+
this.detachCallbacks.forEach((it) => it(terminal));
|
|
873
|
+
this.terminal = void 0;
|
|
874
|
+
}
|
|
875
|
+
input(str, key) {
|
|
876
|
+
this.inputCallbacks.forEach((it) => it(str, key));
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
exports.Prompt = Prompt2;
|
|
880
|
+
var SelectState2 = class {
|
|
881
|
+
constructor(items) {
|
|
882
|
+
this.items = items;
|
|
883
|
+
this.selectedIdx = 0;
|
|
884
|
+
}
|
|
885
|
+
bind(prompt) {
|
|
886
|
+
prompt.on("input", (str, key) => {
|
|
887
|
+
const invalidate = this.consume(str, key);
|
|
888
|
+
if (invalidate)
|
|
889
|
+
prompt.requestLayout();
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
consume(str, key) {
|
|
893
|
+
if (!key)
|
|
894
|
+
return false;
|
|
895
|
+
if (key.name === "down") {
|
|
896
|
+
this.selectedIdx = (this.selectedIdx + 1) % this.items.length;
|
|
897
|
+
return true;
|
|
898
|
+
}
|
|
899
|
+
if (key.name === "up") {
|
|
900
|
+
this.selectedIdx -= 1;
|
|
901
|
+
this.selectedIdx = this.selectedIdx < 0 ? this.items.length - 1 : this.selectedIdx;
|
|
902
|
+
return true;
|
|
967
903
|
}
|
|
904
|
+
return false;
|
|
968
905
|
}
|
|
969
906
|
};
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
} else if (type === "serial") {
|
|
1009
|
-
columnBuilder = new import_pg_core.PgSerialBuilder(columnName);
|
|
1010
|
-
} else if (type === "smallint") {
|
|
1011
|
-
columnBuilder = new import_pg_core.PgSmallIntBuilder(columnName);
|
|
1012
|
-
} else if (type === "smallserial") {
|
|
1013
|
-
columnBuilder = new import_pg_core.PgSmallSerialBuilder(columnName);
|
|
1014
|
-
} else if (type === "text") {
|
|
1015
|
-
columnBuilder = new import_pg_core.PgTextBuilder(columnName, {});
|
|
1016
|
-
} else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
|
|
1017
|
-
columnBuilder = new import_pg_core.PgTimeBuilder(columnName, false, void 0);
|
|
1018
|
-
} else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
|
|
1019
|
-
columnBuilder = new import_pg_core.PgTimestampBuilder(columnName, false, void 0);
|
|
1020
|
-
} else if (type === "uuid") {
|
|
1021
|
-
columnBuilder = new import_pg_core.PgUUIDBuilder(columnName);
|
|
1022
|
-
} else if (type === "varchar" || type.startsWith("varchar(")) {
|
|
1023
|
-
columnBuilder = new import_pg_core.PgVarcharBuilder(columnName, {});
|
|
1024
|
-
} else if (type === "char" || type.startsWith("char(")) {
|
|
1025
|
-
columnBuilder = new import_pg_core.PgCharBuilder(columnName, {});
|
|
1026
|
-
} else {
|
|
1027
|
-
columnBuilder = (0, import_pg_core.customType)({
|
|
1028
|
-
dataType() {
|
|
1029
|
-
return type;
|
|
1030
|
-
}
|
|
1031
|
-
})(columnName);
|
|
1032
|
-
}
|
|
1033
|
-
if (c.notNull) {
|
|
1034
|
-
columnBuilder = columnBuilder.notNull();
|
|
907
|
+
exports.SelectState = SelectState2;
|
|
908
|
+
var deferred = () => {
|
|
909
|
+
let resolve;
|
|
910
|
+
let reject;
|
|
911
|
+
const promise = new Promise((res, rej) => {
|
|
912
|
+
resolve = res;
|
|
913
|
+
reject = rej;
|
|
914
|
+
});
|
|
915
|
+
return {
|
|
916
|
+
resolve,
|
|
917
|
+
reject,
|
|
918
|
+
promise
|
|
919
|
+
};
|
|
920
|
+
};
|
|
921
|
+
exports.deferred = deferred;
|
|
922
|
+
var Terminal = class {
|
|
923
|
+
constructor(view, stdin, stdout, closable) {
|
|
924
|
+
this.view = view;
|
|
925
|
+
this.stdin = stdin;
|
|
926
|
+
this.stdout = stdout;
|
|
927
|
+
this.closable = closable;
|
|
928
|
+
this.text = "";
|
|
929
|
+
this.status = "idle";
|
|
930
|
+
if (this.stdin.isTTY)
|
|
931
|
+
this.stdin.setRawMode(true);
|
|
932
|
+
const keypress = (str, key) => {
|
|
933
|
+
if (key.name === "c" && key.ctrl === true) {
|
|
934
|
+
this.requestLayout();
|
|
935
|
+
this.view.detach(this);
|
|
936
|
+
this.tearDown(keypress);
|
|
937
|
+
if (terminateHandler) {
|
|
938
|
+
terminateHandler(this.stdin, this.stdout);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
this.stdout.write(`
|
|
942
|
+
^C
|
|
943
|
+
`);
|
|
944
|
+
process.exit(1);
|
|
1035
945
|
}
|
|
1036
|
-
if (
|
|
1037
|
-
|
|
946
|
+
if (key.name === "escape") {
|
|
947
|
+
this.status = "aborted";
|
|
948
|
+
this.requestLayout();
|
|
949
|
+
this.view.detach(this);
|
|
950
|
+
this.tearDown(keypress);
|
|
951
|
+
this.resolve({ status: "aborted", data: void 0 });
|
|
952
|
+
return;
|
|
1038
953
|
}
|
|
1039
|
-
if (
|
|
1040
|
-
|
|
954
|
+
if (key.name === "return") {
|
|
955
|
+
this.status = "submitted";
|
|
956
|
+
this.requestLayout();
|
|
957
|
+
this.view.detach(this);
|
|
958
|
+
this.tearDown(keypress);
|
|
959
|
+
this.resolve({ status: "submitted", data: this.view.result() });
|
|
960
|
+
return;
|
|
1041
961
|
}
|
|
1042
|
-
|
|
962
|
+
view.input(str, key);
|
|
963
|
+
};
|
|
964
|
+
this.stdin.on("keypress", keypress);
|
|
965
|
+
this.view.attach(this);
|
|
966
|
+
const { resolve, promise } = (0, exports.deferred)();
|
|
967
|
+
this.resolve = resolve;
|
|
968
|
+
this.promise = promise;
|
|
969
|
+
this.renderFunc = (0, lodash_throttle_1.default)((str) => {
|
|
970
|
+
this.stdout.write(str);
|
|
1043
971
|
});
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
972
|
+
}
|
|
973
|
+
tearDown(keypress) {
|
|
974
|
+
this.stdout.write(sisteransi_1.cursor.show);
|
|
975
|
+
this.stdin.removeListener("keypress", keypress);
|
|
976
|
+
if (this.stdin.isTTY)
|
|
977
|
+
this.stdin.setRawMode(false);
|
|
978
|
+
this.closable.close();
|
|
979
|
+
}
|
|
980
|
+
result() {
|
|
981
|
+
return this.promise;
|
|
982
|
+
}
|
|
983
|
+
toggleCursor(state) {
|
|
984
|
+
if (state === "hide") {
|
|
985
|
+
this.stdout.write(sisteransi_1.cursor.hide);
|
|
1056
986
|
} else {
|
|
1057
|
-
|
|
1058
|
-
const res = {};
|
|
1059
|
-
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
|
1060
|
-
const gh = cpk.columns.map((c) => cb[c]);
|
|
1061
|
-
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
|
1062
|
-
gh,
|
|
1063
|
-
cpk.name
|
|
1064
|
-
);
|
|
1065
|
-
});
|
|
1066
|
-
return res;
|
|
1067
|
-
});
|
|
987
|
+
this.stdout.write(sisteransi_1.cursor.show);
|
|
1068
988
|
}
|
|
1069
|
-
}
|
|
1070
|
-
|
|
989
|
+
}
|
|
990
|
+
requestLayout() {
|
|
991
|
+
const string = this.view.render(this.status);
|
|
992
|
+
const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
|
|
993
|
+
this.text = string;
|
|
994
|
+
this.renderFunc(`${clearPrefix}${string}`);
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
exports.Terminal = Terminal;
|
|
998
|
+
var TaskView2 = class {
|
|
999
|
+
constructor() {
|
|
1000
|
+
this.attachCallbacks = [];
|
|
1001
|
+
this.detachCallbacks = [];
|
|
1002
|
+
}
|
|
1003
|
+
requestLayout() {
|
|
1004
|
+
this.terminal.requestLayout();
|
|
1005
|
+
}
|
|
1006
|
+
attach(terminal) {
|
|
1007
|
+
this.terminal = terminal;
|
|
1008
|
+
this.attachCallbacks.forEach((it) => it(terminal));
|
|
1009
|
+
}
|
|
1010
|
+
detach(terminal) {
|
|
1011
|
+
this.detachCallbacks.forEach((it) => it(terminal));
|
|
1012
|
+
this.terminal = void 0;
|
|
1013
|
+
}
|
|
1014
|
+
on(type, callback) {
|
|
1015
|
+
if (type === "attach") {
|
|
1016
|
+
this.attachCallbacks.push(callback);
|
|
1017
|
+
} else if (type === "detach") {
|
|
1018
|
+
this.detachCallbacks.push(callback);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
exports.TaskView = TaskView2;
|
|
1023
|
+
var TaskTerminal = class {
|
|
1024
|
+
constructor(view, stdout) {
|
|
1025
|
+
this.view = view;
|
|
1026
|
+
this.stdout = stdout;
|
|
1027
|
+
this.text = "";
|
|
1028
|
+
this.view.attach(this);
|
|
1029
|
+
}
|
|
1030
|
+
requestLayout() {
|
|
1031
|
+
const string = this.view.render("pending");
|
|
1032
|
+
const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
|
|
1033
|
+
this.text = string;
|
|
1034
|
+
this.stdout.write(`${clearPrefix}${string}`);
|
|
1035
|
+
}
|
|
1036
|
+
clear() {
|
|
1037
|
+
const string = this.view.render("done");
|
|
1038
|
+
this.view.detach(this);
|
|
1039
|
+
const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
|
|
1040
|
+
this.stdout.write(`${clearPrefix}${string}`);
|
|
1041
|
+
}
|
|
1071
1042
|
};
|
|
1043
|
+
exports.TaskTerminal = TaskTerminal;
|
|
1044
|
+
function render2(view) {
|
|
1045
|
+
const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
|
|
1046
|
+
if (view instanceof Prompt2) {
|
|
1047
|
+
const terminal = new Terminal(view, stdin, stdout, closable);
|
|
1048
|
+
terminal.requestLayout();
|
|
1049
|
+
return terminal.result();
|
|
1050
|
+
}
|
|
1051
|
+
stdout.write(`${view}
|
|
1052
|
+
`);
|
|
1053
|
+
closable.close();
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
exports.render = render2;
|
|
1057
|
+
function renderWithTask3(view, task) {
|
|
1058
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1059
|
+
const terminal = new TaskTerminal(view, process.stdout);
|
|
1060
|
+
terminal.requestLayout();
|
|
1061
|
+
const result = yield task;
|
|
1062
|
+
terminal.clear();
|
|
1063
|
+
return result;
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
exports.renderWithTask = renderWithTask3;
|
|
1067
|
+
var terminateHandler;
|
|
1068
|
+
function onTerminate(callback) {
|
|
1069
|
+
terminateHandler = callback;
|
|
1070
|
+
}
|
|
1071
|
+
exports.onTerminate = onTerminate;
|
|
1072
1072
|
}
|
|
1073
1073
|
});
|
|
1074
1074
|
|
|
1075
|
-
// src/
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
"tinyint",
|
|
1082
|
-
"smallint",
|
|
1083
|
-
"mediumint",
|
|
1084
|
-
"bigint",
|
|
1085
|
-
"unsigned big int",
|
|
1086
|
-
"int2",
|
|
1087
|
-
"int8"
|
|
1088
|
-
].includes(sqlType.toLowerCase())) {
|
|
1089
|
-
return "integer";
|
|
1090
|
-
} else if ([
|
|
1091
|
-
"character",
|
|
1092
|
-
"varchar",
|
|
1093
|
-
"vatying character",
|
|
1094
|
-
"nchar",
|
|
1095
|
-
"native character",
|
|
1096
|
-
"nvarchar",
|
|
1097
|
-
"text",
|
|
1098
|
-
"clob"
|
|
1099
|
-
].some((it) => it.startsWith(sqlType.toLowerCase()))) {
|
|
1100
|
-
return "text";
|
|
1101
|
-
} else if (sqlType.toLowerCase() === "blob") {
|
|
1102
|
-
return "blob";
|
|
1103
|
-
} else if (["real", "double", "double precision", "float"].includes(
|
|
1104
|
-
sqlType.toLowerCase()
|
|
1105
|
-
)) {
|
|
1106
|
-
return "real";
|
|
1107
|
-
} else {
|
|
1108
|
-
return "numeric";
|
|
1075
|
+
// src/cli/views.ts
|
|
1076
|
+
var import_hanji;
|
|
1077
|
+
var init_views = __esm({
|
|
1078
|
+
"src/cli/views.ts"() {
|
|
1079
|
+
init_source();
|
|
1080
|
+
import_hanji = __toESM(require_hanji());
|
|
1109
1081
|
}
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
// src/serializer/index.ts
|
|
1085
|
+
var glob;
|
|
1086
|
+
var init_serializer = __esm({
|
|
1087
|
+
"src/serializer/index.ts"() {
|
|
1088
|
+
glob = __toESM(require("glob"));
|
|
1089
|
+
init_source();
|
|
1090
|
+
init_views();
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
// src/cli/validations/outputs.ts
|
|
1095
|
+
var init_outputs = __esm({
|
|
1096
|
+
"src/cli/validations/outputs.ts"() {
|
|
1097
|
+
init_source();
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
// src/serializer/pgSerializer.ts
|
|
1102
|
+
var import_pg_core, import_pg_core2, import_drizzle_orm, dialect, trimChar, fromDatabase, columnToDefault, defaultForColumn, toDrizzle;
|
|
1103
|
+
var init_pgSerializer = __esm({
|
|
1104
|
+
"src/serializer/pgSerializer.ts"() {
|
|
1105
|
+
import_pg_core = require("drizzle-orm/pg-core");
|
|
1106
|
+
import_pg_core2 = require("drizzle-orm/pg-core");
|
|
1107
|
+
import_drizzle_orm = require("drizzle-orm");
|
|
1116
1108
|
init_serializer();
|
|
1117
|
-
init_outputs();
|
|
1118
1109
|
init_source();
|
|
1119
|
-
|
|
1120
|
-
|
|
1110
|
+
init_outputs();
|
|
1111
|
+
dialect = new import_pg_core.PgDialect();
|
|
1112
|
+
trimChar = (str, char) => {
|
|
1113
|
+
let start = 0;
|
|
1114
|
+
let end = str.length;
|
|
1115
|
+
while (start < end && str[start] === char)
|
|
1116
|
+
++start;
|
|
1117
|
+
while (end > start && str[end - 1] === char)
|
|
1118
|
+
--end;
|
|
1119
|
+
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
|
1120
|
+
};
|
|
1121
|
+
fromDatabase = async (db, tablesFilter = (table) => true, schemaFilters, progressCallback) => {
|
|
1121
1122
|
const result = {};
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
WHERE m.type = 'table' and m.tbl_name != 'sqlite_sequence' and m.tbl_name != 'sqlite_stat1' and m.tbl_name != '_litestream_seq' and m.tbl_name != '_litestream_lock' and m.tbl_name != 'libsql_wasm_func_table';
|
|
1127
|
-
`
|
|
1128
|
-
);
|
|
1129
|
-
const tablesWithSeq = [];
|
|
1130
|
-
const seq = await db.query(
|
|
1131
|
-
`SELECT * FROM sqlite_master WHERE name != 'sqlite_sequence' and name != 'sqlite_stat1' and name != '_litestream_seq' and name != '_litestream_lock' and sql GLOB '*[ *' || CHAR(9) || CHAR(10) || CHAR(13) || ']AUTOINCREMENT[^'']*';`
|
|
1123
|
+
const internals = { tables: {} };
|
|
1124
|
+
const where = schemaFilters.map((t) => `table_schema = '${t}'`).join(" or ");
|
|
1125
|
+
const allTables = await db.query(
|
|
1126
|
+
`SELECT table_schema, table_name FROM information_schema.tables WHERE ${where};`
|
|
1132
1127
|
);
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1128
|
+
const schemas = new Set(allTables.map((it) => it.table_schema));
|
|
1129
|
+
schemas.delete("public");
|
|
1130
|
+
const allSchemas = await db.query(`select s.nspname as table_schema
|
|
1131
|
+
from pg_catalog.pg_namespace s
|
|
1132
|
+
join pg_catalog.pg_user u on u.usesysid = s.nspowner
|
|
1133
|
+
where nspname not in ('information_schema', 'pg_catalog', 'public')
|
|
1134
|
+
and nspname not like 'pg_toast%'
|
|
1135
|
+
and nspname not like 'pg_temp_%'
|
|
1136
|
+
order by table_schema;`);
|
|
1137
|
+
allSchemas.forEach((item) => {
|
|
1138
|
+
if (schemaFilters.includes(item.table_schema)) {
|
|
1139
|
+
schemas.add(item.table_schema);
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1136
1142
|
let columnsCount = 0;
|
|
1137
|
-
let tablesCount = /* @__PURE__ */ new Set();
|
|
1138
1143
|
let indexesCount = 0;
|
|
1139
1144
|
let foreignKeysCount = 0;
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
result[tableName].columns[columnName] = newColumn;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
for (const [key, value] of Object.entries(tableToPk)) {
|
|
1196
|
-
if (value.length > 1) {
|
|
1197
|
-
value.sort();
|
|
1198
|
-
result[key].compositePrimaryKeys = {
|
|
1199
|
-
[`${key}_${value.join("_")}_pk`]: {
|
|
1200
|
-
columns: value,
|
|
1201
|
-
name: `${key}_${value.join("_")}_pk`
|
|
1145
|
+
let tableCount = 0;
|
|
1146
|
+
const all = allTables.map((row) => {
|
|
1147
|
+
return new Promise(async (res, rej) => {
|
|
1148
|
+
const tableName = row.table_name;
|
|
1149
|
+
if (!tablesFilter(tableName))
|
|
1150
|
+
return res("");
|
|
1151
|
+
tableCount += 1;
|
|
1152
|
+
const tableSchema = row.table_schema;
|
|
1153
|
+
try {
|
|
1154
|
+
const columnToReturn = {};
|
|
1155
|
+
const indexToReturn = {};
|
|
1156
|
+
const foreignKeysToReturn = {};
|
|
1157
|
+
const primaryKeys = {};
|
|
1158
|
+
const uniqueConstrains = {};
|
|
1159
|
+
const tableResponse = await db.query(
|
|
1160
|
+
`SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
|
|
1161
|
+
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
|
1162
|
+
AND EXISTS (
|
|
1163
|
+
SELECT FROM pg_attrdef ad
|
|
1164
|
+
WHERE ad.adrelid = a.attrelid
|
|
1165
|
+
AND ad.adnum = a.attnum
|
|
1166
|
+
AND pg_get_expr(ad.adbin, ad.adrelid)
|
|
1167
|
+
= 'nextval('''
|
|
1168
|
+
|| (pg_get_serial_sequence (a.attrelid::regclass::text
|
|
1169
|
+
, a.attname))::regclass
|
|
1170
|
+
|| '''::regclass)'
|
|
1171
|
+
)
|
|
1172
|
+
THEN CASE a.atttypid
|
|
1173
|
+
WHEN 'int'::regtype THEN 'serial'
|
|
1174
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
|
1175
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
|
1176
|
+
END
|
|
1177
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
|
1178
|
+
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, INFORMATION_SCHEMA.COLUMNS.column_name, INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt
|
|
1179
|
+
FROM pg_attribute a
|
|
1180
|
+
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
|
1181
|
+
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}'
|
|
1182
|
+
AND a.attnum > 0
|
|
1183
|
+
AND NOT a.attisdropped
|
|
1184
|
+
ORDER BY a.attnum;`
|
|
1185
|
+
);
|
|
1186
|
+
const tableConstraints = await db.query(
|
|
1187
|
+
`SELECT c.column_name, c.data_type, constraint_type, constraint_name, constraint_schema
|
|
1188
|
+
FROM information_schema.table_constraints tc
|
|
1189
|
+
JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
|
|
1190
|
+
JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema
|
|
1191
|
+
AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
|
|
1192
|
+
WHERE tc.table_name = '${tableName}' and constraint_schema = '${tableSchema}';`
|
|
1193
|
+
);
|
|
1194
|
+
columnsCount += tableResponse.length;
|
|
1195
|
+
if (progressCallback) {
|
|
1196
|
+
progressCallback("columns", columnsCount, "fetching");
|
|
1202
1197
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
const tableName = fkRow.tableFrom;
|
|
1225
|
-
const columnName = fkRow.from;
|
|
1226
|
-
const refTableName = fkRow.tableTo;
|
|
1227
|
-
const refColumnName = fkRow.to;
|
|
1228
|
-
const updateRule = fkRow.onUpdate;
|
|
1229
|
-
const deleteRule = fkRow.onDelete;
|
|
1230
|
-
const sequence = fkRow.seq;
|
|
1231
|
-
const id = fkRow.id;
|
|
1232
|
-
const tableInResult = result[tableName];
|
|
1233
|
-
if (typeof tableInResult === "undefined")
|
|
1234
|
-
continue;
|
|
1235
|
-
if (typeof fkByTableName[`${tableName}_${id}`] !== "undefined") {
|
|
1236
|
-
fkByTableName[`${tableName}_${id}`].columnsFrom.push(columnName);
|
|
1237
|
-
fkByTableName[`${tableName}_${id}`].columnsTo.push(refColumnName);
|
|
1238
|
-
} else {
|
|
1239
|
-
fkByTableName[`${tableName}_${id}`] = {
|
|
1240
|
-
name: "",
|
|
1241
|
-
tableFrom: tableName,
|
|
1242
|
-
tableTo: refTableName,
|
|
1243
|
-
columnsFrom: [columnName],
|
|
1244
|
-
columnsTo: [refColumnName],
|
|
1245
|
-
onDelete: deleteRule == null ? void 0 : deleteRule.toLowerCase(),
|
|
1246
|
-
onUpdate: updateRule == null ? void 0 : updateRule.toLowerCase()
|
|
1247
|
-
};
|
|
1248
|
-
}
|
|
1249
|
-
const columnsFrom = fkByTableName[`${tableName}_${id}`].columnsFrom;
|
|
1250
|
-
const columnsTo = fkByTableName[`${tableName}_${id}`].columnsTo;
|
|
1251
|
-
fkByTableName[`${tableName}_${id}`].name = `${tableName}_${columnsFrom.join(
|
|
1252
|
-
"_"
|
|
1253
|
-
)}_${refTableName}_${columnsTo.join("_")}_fk`;
|
|
1254
|
-
}
|
|
1255
|
-
for (const idx of Object.keys(fkByTableName)) {
|
|
1256
|
-
const value = fkByTableName[idx];
|
|
1257
|
-
result[value.tableFrom].foreignKeys[value.name] = value;
|
|
1258
|
-
}
|
|
1259
|
-
} catch (e) {
|
|
1260
|
-
}
|
|
1261
|
-
if (progressCallback) {
|
|
1262
|
-
progressCallback("fks", foreignKeysCount, "done");
|
|
1263
|
-
}
|
|
1264
|
-
const idxs = await db.query(
|
|
1265
|
-
`SELECT
|
|
1266
|
-
m.tbl_name as tableName,
|
|
1267
|
-
il.name as indexName,
|
|
1268
|
-
ii.name as columnName,
|
|
1269
|
-
il.[unique] as isUnique,
|
|
1270
|
-
il.seq as seq
|
|
1271
|
-
FROM sqlite_master AS m,
|
|
1272
|
-
pragma_index_list(m.name) AS il,
|
|
1273
|
-
pragma_index_info(il.name) AS ii
|
|
1274
|
-
WHERE
|
|
1275
|
-
m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
|
|
1276
|
-
);
|
|
1277
|
-
for (const idxRow of idxs) {
|
|
1278
|
-
const tableName = idxRow.tableName;
|
|
1279
|
-
const constraintName = idxRow.indexName;
|
|
1280
|
-
const columnName = idxRow.columnName;
|
|
1281
|
-
const isUnique = idxRow.isUnique === 1;
|
|
1282
|
-
const tableInResult = result[tableName];
|
|
1283
|
-
if (typeof tableInResult === "undefined")
|
|
1284
|
-
continue;
|
|
1285
|
-
indexesCount += 1;
|
|
1286
|
-
if (progressCallback) {
|
|
1287
|
-
progressCallback("indexes", indexesCount, "fetching");
|
|
1288
|
-
}
|
|
1289
|
-
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
|
1290
|
-
tableInResult.indexes[constraintName].columns.push(columnName);
|
|
1291
|
-
} else {
|
|
1292
|
-
tableInResult.indexes[constraintName] = {
|
|
1293
|
-
name: constraintName,
|
|
1294
|
-
columns: [columnName],
|
|
1295
|
-
isUnique
|
|
1296
|
-
};
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
if (progressCallback) {
|
|
1300
|
-
progressCallback("indexes", indexesCount, "done");
|
|
1301
|
-
progressCallback("enums", 0, "done");
|
|
1302
|
-
}
|
|
1303
|
-
return {
|
|
1304
|
-
version: "5",
|
|
1305
|
-
dialect: "sqlite",
|
|
1306
|
-
tables: result,
|
|
1307
|
-
enums: {},
|
|
1308
|
-
_meta: {
|
|
1309
|
-
tables: {},
|
|
1310
|
-
columns: {}
|
|
1311
|
-
}
|
|
1312
|
-
};
|
|
1313
|
-
};
|
|
1314
|
-
toDrizzle2 = (schema) => {
|
|
1315
|
-
const tables = {};
|
|
1316
|
-
Object.values(schema.tables).forEach((t) => {
|
|
1317
|
-
const columns = {};
|
|
1318
|
-
Object.values(t.columns).forEach((c) => {
|
|
1319
|
-
const columnName = c.name;
|
|
1320
|
-
const type = c.type;
|
|
1321
|
-
let columnBuilder;
|
|
1322
|
-
if (type === "integer") {
|
|
1323
|
-
columnBuilder = new import_sqlite_core.SQLiteIntegerBuilder(columnName);
|
|
1324
|
-
} else if (type === "text") {
|
|
1325
|
-
columnBuilder = new import_sqlite_core.SQLiteTextBuilder(columnName, {});
|
|
1326
|
-
} else if (type === "blob") {
|
|
1327
|
-
columnBuilder = new import_sqlite_core.SQLiteBlobBufferBuilder(columnName);
|
|
1328
|
-
} else if (type === "real") {
|
|
1329
|
-
columnBuilder = new import_sqlite_core.SQLiteRealBuilder(columnName);
|
|
1330
|
-
} else {
|
|
1331
|
-
columnBuilder = new import_sqlite_core.SQLiteNumericBuilder(columnName);
|
|
1332
|
-
}
|
|
1333
|
-
if (c.notNull) {
|
|
1334
|
-
columnBuilder = columnBuilder.notNull();
|
|
1335
|
-
}
|
|
1336
|
-
if (c.default) {
|
|
1337
|
-
columnBuilder = columnBuilder.default(c.default);
|
|
1338
|
-
}
|
|
1339
|
-
if (c.primaryKey) {
|
|
1340
|
-
columnBuilder = columnBuilder.primaryKey();
|
|
1341
|
-
}
|
|
1342
|
-
columns[columnName] = columnBuilder;
|
|
1343
|
-
});
|
|
1344
|
-
tables[t.name] = (0, import_sqlite_core.sqliteTable)(t.name, columns, (cb) => {
|
|
1345
|
-
const res = {};
|
|
1346
|
-
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
|
1347
|
-
const gh = cpk.columns.map((c) => cb[c]);
|
|
1348
|
-
res[cpk.name] = new import_sqlite_core.PrimaryKeyBuilder(
|
|
1349
|
-
gh,
|
|
1350
|
-
cpk.name
|
|
1198
|
+
const tableForeignKeys = await db.query(
|
|
1199
|
+
`SELECT
|
|
1200
|
+
tc.table_schema,
|
|
1201
|
+
tc.constraint_name,
|
|
1202
|
+
tc.table_name,
|
|
1203
|
+
kcu.column_name,
|
|
1204
|
+
ccu.table_schema AS foreign_table_schema,
|
|
1205
|
+
ccu.table_name AS foreign_table_name,
|
|
1206
|
+
ccu.column_name AS foreign_column_name,
|
|
1207
|
+
rc.delete_rule, rc.update_rule
|
|
1208
|
+
FROM
|
|
1209
|
+
information_schema.table_constraints AS tc
|
|
1210
|
+
JOIN information_schema.key_column_usage AS kcu
|
|
1211
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
1212
|
+
AND tc.table_schema = kcu.table_schema
|
|
1213
|
+
JOIN information_schema.constraint_column_usage AS ccu
|
|
1214
|
+
ON ccu.constraint_name = tc.constraint_name
|
|
1215
|
+
AND ccu.table_schema = tc.table_schema
|
|
1216
|
+
JOIN information_schema.referential_constraints AS rc
|
|
1217
|
+
ON ccu.constraint_name = rc.constraint_name
|
|
1218
|
+
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
|
|
1351
1219
|
);
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
return trailingEdge(time);
|
|
1534
|
-
}
|
|
1535
|
-
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
1536
|
-
}
|
|
1537
|
-
function trailingEdge(time) {
|
|
1538
|
-
timerId = void 0;
|
|
1539
|
-
if (trailing && lastArgs) {
|
|
1540
|
-
return invokeFunc(time);
|
|
1541
|
-
}
|
|
1542
|
-
lastArgs = lastThis = void 0;
|
|
1543
|
-
return result;
|
|
1544
|
-
}
|
|
1545
|
-
function cancel() {
|
|
1546
|
-
if (timerId !== void 0) {
|
|
1547
|
-
clearTimeout(timerId);
|
|
1548
|
-
}
|
|
1549
|
-
lastInvokeTime = 0;
|
|
1550
|
-
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
1551
|
-
}
|
|
1552
|
-
function flush() {
|
|
1553
|
-
return timerId === void 0 ? result : trailingEdge(now());
|
|
1554
|
-
}
|
|
1555
|
-
function debounced() {
|
|
1556
|
-
var time = now(), isInvoking = shouldInvoke(time);
|
|
1557
|
-
lastArgs = arguments;
|
|
1558
|
-
lastThis = this;
|
|
1559
|
-
lastCallTime = time;
|
|
1560
|
-
if (isInvoking) {
|
|
1561
|
-
if (timerId === void 0) {
|
|
1562
|
-
return leadingEdge(lastCallTime);
|
|
1563
|
-
}
|
|
1564
|
-
if (maxing) {
|
|
1565
|
-
timerId = setTimeout(timerExpired, wait);
|
|
1566
|
-
return invokeFunc(lastCallTime);
|
|
1220
|
+
foreignKeysCount += tableForeignKeys.length;
|
|
1221
|
+
if (progressCallback) {
|
|
1222
|
+
progressCallback("fks", foreignKeysCount, "fetching");
|
|
1223
|
+
}
|
|
1224
|
+
for (const fk of tableForeignKeys) {
|
|
1225
|
+
const columnFrom = fk.column_name;
|
|
1226
|
+
const tableTo = fk.foreign_table_name;
|
|
1227
|
+
const columnTo = fk.foreign_column_name;
|
|
1228
|
+
const foreignKeyName = fk.constraint_name;
|
|
1229
|
+
const onUpdate = fk.update_rule.toLowerCase();
|
|
1230
|
+
const onDelete = fk.delete_rule.toLowerCase();
|
|
1231
|
+
if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
|
|
1232
|
+
foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
|
|
1233
|
+
foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
|
|
1234
|
+
} else {
|
|
1235
|
+
foreignKeysToReturn[foreignKeyName] = {
|
|
1236
|
+
name: foreignKeyName,
|
|
1237
|
+
tableFrom: tableName,
|
|
1238
|
+
tableTo,
|
|
1239
|
+
columnsFrom: [columnFrom],
|
|
1240
|
+
columnsTo: [columnTo],
|
|
1241
|
+
onDelete,
|
|
1242
|
+
onUpdate
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
foreignKeysToReturn[foreignKeyName].columnsFrom = [
|
|
1246
|
+
...new Set(foreignKeysToReturn[foreignKeyName].columnsFrom)
|
|
1247
|
+
];
|
|
1248
|
+
foreignKeysToReturn[foreignKeyName].columnsTo = [
|
|
1249
|
+
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
|
1250
|
+
];
|
|
1251
|
+
}
|
|
1252
|
+
const uniqueConstrainsRows = tableConstraints.filter(
|
|
1253
|
+
(mapRow) => mapRow.constraint_type === "UNIQUE"
|
|
1254
|
+
);
|
|
1255
|
+
for (const unqs of uniqueConstrainsRows) {
|
|
1256
|
+
const columnName = unqs.column_name;
|
|
1257
|
+
const constraintName = unqs.constraint_name;
|
|
1258
|
+
if (typeof uniqueConstrains[constraintName] !== "undefined") {
|
|
1259
|
+
uniqueConstrains[constraintName].columns.push(columnName);
|
|
1260
|
+
} else {
|
|
1261
|
+
uniqueConstrains[constraintName] = {
|
|
1262
|
+
columns: [columnName],
|
|
1263
|
+
nullsNotDistinct: false,
|
|
1264
|
+
name: constraintName
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
for (const columnResponse of tableResponse) {
|
|
1269
|
+
const columnName = columnResponse.attname;
|
|
1270
|
+
const columnAdditionalDT = columnResponse.additional_dt;
|
|
1271
|
+
const columnDimensions = columnResponse.array_dimensions;
|
|
1272
|
+
let columnType = columnResponse.data_type;
|
|
1273
|
+
const primaryKey = tableConstraints.filter(
|
|
1274
|
+
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
|
|
1275
|
+
);
|
|
1276
|
+
const cprimaryKey = tableConstraints.filter(
|
|
1277
|
+
(mapRow) => mapRow.constraint_type === "PRIMARY KEY"
|
|
1278
|
+
);
|
|
1279
|
+
if (cprimaryKey.length > 1) {
|
|
1280
|
+
const tableCompositePkName = await db.query(
|
|
1281
|
+
`SELECT conname AS primary_key
|
|
1282
|
+
FROM pg_constraint join pg_class on (pg_class.oid = conrelid)
|
|
1283
|
+
WHERE contype = 'p'
|
|
1284
|
+
AND connamespace = $1::regnamespace
|
|
1285
|
+
AND pg_class.relname = $2;`,
|
|
1286
|
+
[tableSchema, tableName]
|
|
1287
|
+
);
|
|
1288
|
+
primaryKeys[tableCompositePkName[0].primary_key] = {
|
|
1289
|
+
name: tableCompositePkName[0].primary_key,
|
|
1290
|
+
columns: cprimaryKey.map((c) => c.column_name)
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
const defaultValue = defaultForColumn(columnResponse);
|
|
1294
|
+
const isSerial = columnType === "serial";
|
|
1295
|
+
let columnTypeMapped = columnType;
|
|
1296
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
|
1297
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
|
1298
|
+
}
|
|
1299
|
+
if (columnAdditionalDT === "ARRAY") {
|
|
1300
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
|
1301
|
+
internals.tables[tableName] = {
|
|
1302
|
+
columns: {
|
|
1303
|
+
[columnName]: {
|
|
1304
|
+
isArray: true,
|
|
1305
|
+
dimensions: columnDimensions,
|
|
1306
|
+
rawType: columnTypeMapped.substring(
|
|
1307
|
+
0,
|
|
1308
|
+
columnTypeMapped.length - 2
|
|
1309
|
+
)
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
} else {
|
|
1314
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
|
1315
|
+
internals.tables[tableName].columns[columnName] = {
|
|
1316
|
+
isArray: true,
|
|
1317
|
+
dimensions: columnDimensions,
|
|
1318
|
+
rawType: columnTypeMapped.substring(
|
|
1319
|
+
0,
|
|
1320
|
+
columnTypeMapped.length - 2
|
|
1321
|
+
)
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
if (columnAdditionalDT === "ARRAY") {
|
|
1327
|
+
for (let i = 1; i < Number(columnDimensions); i++) {
|
|
1328
|
+
columnTypeMapped += "[]";
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
|
|
1332
|
+
columnTypeMapped = trimChar(columnTypeMapped, '"');
|
|
1333
|
+
columnToReturn[columnName] = {
|
|
1334
|
+
name: columnName,
|
|
1335
|
+
type: columnTypeMapped,
|
|
1336
|
+
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
|
1337
|
+
// default: isSerial ? undefined : defaultValue,
|
|
1338
|
+
notNull: columnResponse.is_nullable === "NO"
|
|
1339
|
+
};
|
|
1340
|
+
if (!isSerial && typeof defaultValue !== "undefined") {
|
|
1341
|
+
columnToReturn[columnName].default = defaultValue;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
const dbIndexes = await db.query(
|
|
1345
|
+
`SELECT t.relname as table_name, i.relname AS index_name, ix.indisunique AS is_unique, a.attname AS column_name
|
|
1346
|
+
FROM pg_class t
|
|
1347
|
+
JOIN pg_index ix ON t.oid = ix.indrelid
|
|
1348
|
+
JOIN pg_class i ON i.oid = ix.indexrelid
|
|
1349
|
+
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
|
|
1350
|
+
JOIN pg_namespace ns ON ns.oid = t.relnamespace
|
|
1351
|
+
WHERE ns.nspname = '${tableSchema}'
|
|
1352
|
+
AND t.relname = '${tableName}'
|
|
1353
|
+
and ix.indisprimary = false;`
|
|
1354
|
+
);
|
|
1355
|
+
const dbIndexFromConstraint = await db.query(
|
|
1356
|
+
`SELECT
|
|
1357
|
+
idx.indexrelname AS index_name,
|
|
1358
|
+
idx.relname AS table_name,
|
|
1359
|
+
schemaname,
|
|
1360
|
+
CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 END AS generated_by_constraint
|
|
1361
|
+
FROM
|
|
1362
|
+
pg_stat_user_indexes idx
|
|
1363
|
+
LEFT JOIN
|
|
1364
|
+
pg_constraint con ON con.conindid = idx.indexrelid
|
|
1365
|
+
WHERE idx.relname = '${tableName}' and schemaname = '${tableSchema}'
|
|
1366
|
+
group by index_name, table_name,schemaname, generated_by_constraint;`
|
|
1367
|
+
);
|
|
1368
|
+
const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
|
|
1369
|
+
for (const dbIndex of dbIndexes) {
|
|
1370
|
+
const indexName2 = dbIndex.index_name;
|
|
1371
|
+
const indexColumnName = dbIndex.column_name;
|
|
1372
|
+
const indexIsUnique = dbIndex.is_unique;
|
|
1373
|
+
if (idxsInConsteraint.includes(indexName2))
|
|
1374
|
+
continue;
|
|
1375
|
+
if (typeof indexToReturn[indexName2] !== "undefined") {
|
|
1376
|
+
indexToReturn[indexName2].columns.push(indexColumnName);
|
|
1377
|
+
} else {
|
|
1378
|
+
indexToReturn[indexName2] = {
|
|
1379
|
+
name: indexName2,
|
|
1380
|
+
columns: [indexColumnName],
|
|
1381
|
+
isUnique: indexIsUnique
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
indexesCount += Object.keys(indexToReturn).length;
|
|
1386
|
+
if (progressCallback) {
|
|
1387
|
+
progressCallback("indexes", indexesCount, "fetching");
|
|
1388
|
+
}
|
|
1389
|
+
result[tableName] = {
|
|
1390
|
+
name: tableName,
|
|
1391
|
+
schema: tableSchema !== "public" ? tableSchema : "",
|
|
1392
|
+
columns: columnToReturn,
|
|
1393
|
+
indexes: indexToReturn,
|
|
1394
|
+
foreignKeys: foreignKeysToReturn,
|
|
1395
|
+
compositePrimaryKeys: primaryKeys,
|
|
1396
|
+
uniqueConstraints: uniqueConstrains
|
|
1397
|
+
};
|
|
1398
|
+
} catch (e) {
|
|
1399
|
+
rej(e);
|
|
1400
|
+
return;
|
|
1567
1401
|
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1402
|
+
res("");
|
|
1403
|
+
});
|
|
1404
|
+
});
|
|
1405
|
+
if (progressCallback) {
|
|
1406
|
+
progressCallback("tables", tableCount, "done");
|
|
1573
1407
|
}
|
|
1574
|
-
|
|
1575
|
-
debounced.flush = flush;
|
|
1576
|
-
return debounced;
|
|
1577
|
-
}
|
|
1578
|
-
function throttle(func, wait, options) {
|
|
1579
|
-
var leading = true, trailing = true;
|
|
1580
|
-
if (typeof func != "function") {
|
|
1581
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
1408
|
+
for await (const _ of all) {
|
|
1582
1409
|
}
|
|
1583
|
-
if (
|
|
1584
|
-
|
|
1585
|
-
|
|
1410
|
+
if (progressCallback) {
|
|
1411
|
+
progressCallback("columns", columnsCount, "done");
|
|
1412
|
+
progressCallback("indexes", indexesCount, "done");
|
|
1413
|
+
progressCallback("fks", foreignKeysCount, "done");
|
|
1586
1414
|
}
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1415
|
+
const allEnums = await db.query(
|
|
1416
|
+
`select n.nspname as enum_schema,
|
|
1417
|
+
t.typname as enum_name,
|
|
1418
|
+
e.enumlabel as enum_value
|
|
1419
|
+
from pg_type t
|
|
1420
|
+
join pg_enum e on t.oid = e.enumtypid
|
|
1421
|
+
join pg_catalog.pg_namespace n ON n.oid = t.typnamespace;`
|
|
1422
|
+
);
|
|
1423
|
+
const enumsToReturn = {};
|
|
1424
|
+
for (const dbEnum of allEnums) {
|
|
1425
|
+
const enumName = dbEnum.enum_name;
|
|
1426
|
+
const enumValue = dbEnum.enum_value;
|
|
1427
|
+
if (enumsToReturn[enumName] !== void 0 && enumsToReturn[enumName] !== null) {
|
|
1428
|
+
enumsToReturn[enumName].values[enumValue] = enumValue;
|
|
1429
|
+
} else {
|
|
1430
|
+
enumsToReturn[enumName] = {
|
|
1431
|
+
name: enumName,
|
|
1432
|
+
values: { [enumValue]: enumValue }
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1606
1435
|
}
|
|
1607
|
-
if (
|
|
1608
|
-
|
|
1436
|
+
if (progressCallback) {
|
|
1437
|
+
progressCallback("enums", Object.keys(enumsToReturn).length, "done");
|
|
1609
1438
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1439
|
+
const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
|
|
1440
|
+
return {
|
|
1441
|
+
version: "5",
|
|
1442
|
+
dialect: "pg",
|
|
1443
|
+
tables: result,
|
|
1444
|
+
enums: enumsToReturn,
|
|
1445
|
+
schemas: schemasObject,
|
|
1446
|
+
_meta: {
|
|
1447
|
+
schemas: {},
|
|
1448
|
+
tables: {},
|
|
1449
|
+
columns: {}
|
|
1450
|
+
},
|
|
1451
|
+
internal: internals
|
|
1452
|
+
};
|
|
1453
|
+
};
|
|
1454
|
+
columnToDefault = {
|
|
1455
|
+
"numeric(": "::numeric",
|
|
1456
|
+
// text: "::text",
|
|
1457
|
+
// "character varying": "::character varying",
|
|
1458
|
+
// "double precision": "::double precision",
|
|
1459
|
+
// "time with time zone": "::time with time zone",
|
|
1460
|
+
"time without time zone": "::time without time zone",
|
|
1461
|
+
// "timestamp with time zone": "::timestamp with time zone",
|
|
1462
|
+
"timestamp without time zone": "::timestamp without time zone",
|
|
1463
|
+
// date: "::date",
|
|
1464
|
+
// interval: "::interval",
|
|
1465
|
+
// character: "::bpchar",
|
|
1466
|
+
// macaddr8: "::macaddr8",
|
|
1467
|
+
// macaddr: "::macaddr",
|
|
1468
|
+
// inet: "::inet",
|
|
1469
|
+
// cidr: "::cidr",
|
|
1470
|
+
// jsonb: "::jsonb",
|
|
1471
|
+
// json: "::json",
|
|
1472
|
+
"character(": "::bpchar"
|
|
1473
|
+
};
|
|
1474
|
+
defaultForColumn = (column) => {
|
|
1475
|
+
if (column.data_type === "serial" || column.data_type === "smallserial" || column.data_type === "bigserial") {
|
|
1476
|
+
return void 0;
|
|
1613
1477
|
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1478
|
+
const hasDifferentDefaultCast = Object.keys(columnToDefault).find(
|
|
1479
|
+
(it) => column.data_type.startsWith(it)
|
|
1480
|
+
);
|
|
1481
|
+
if (column.column_default === null) {
|
|
1482
|
+
return void 0;
|
|
1616
1483
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1484
|
+
const columnDefaultAsString = column.column_default.toString();
|
|
1485
|
+
if (columnDefaultAsString.endsWith(
|
|
1486
|
+
hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column.data_type
|
|
1487
|
+
)) {
|
|
1488
|
+
const nonPrefixPart = column.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`).length - 1;
|
|
1489
|
+
const rt = column.column_default.toString().substring(1, nonPrefixPart);
|
|
1490
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column.data_type.startsWith("numeric")) {
|
|
1491
|
+
return Number(rt);
|
|
1492
|
+
} else if (column.data_type === "json" || column.data_type === "jsonb") {
|
|
1493
|
+
const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
|
|
1494
|
+
return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`}`;
|
|
1495
|
+
} else if (column.data_type === "boolean") {
|
|
1496
|
+
return column.column_default === "true";
|
|
1497
|
+
} else {
|
|
1498
|
+
return `'${rt}'`;
|
|
1499
|
+
}
|
|
1500
|
+
} else {
|
|
1501
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column.data_type.startsWith("numeric")) {
|
|
1502
|
+
return Number(columnDefaultAsString);
|
|
1503
|
+
} else if (column.data_type === "boolean") {
|
|
1504
|
+
return column.column_default === "true";
|
|
1505
|
+
} else {
|
|
1506
|
+
return `${columnDefaultAsString}`;
|
|
1507
|
+
}
|
|
1634
1508
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1509
|
+
};
|
|
1510
|
+
toDrizzle = (schema, schemaName) => {
|
|
1511
|
+
const tables = {};
|
|
1512
|
+
Object.values(schema.tables).forEach((t) => {
|
|
1513
|
+
const columns = {};
|
|
1514
|
+
Object.values(t.columns).forEach((c) => {
|
|
1515
|
+
const columnName = c.name;
|
|
1516
|
+
const type = c.type;
|
|
1517
|
+
let columnBuilder;
|
|
1518
|
+
if (type === "bigint") {
|
|
1519
|
+
columnBuilder = new import_pg_core.PgBigInt53Builder(columnName);
|
|
1520
|
+
} else if (type === "bigserial") {
|
|
1521
|
+
columnBuilder = new import_pg_core.PgBigSerial53Builder(columnName);
|
|
1522
|
+
} else if (type === "boolean") {
|
|
1523
|
+
columnBuilder = new import_pg_core.PgBooleanBuilder(columnName);
|
|
1524
|
+
} else if (type === "cidr") {
|
|
1525
|
+
columnBuilder = new import_pg_core.PgCidrBuilder(columnName);
|
|
1526
|
+
} else if (type === "date") {
|
|
1527
|
+
columnBuilder = new import_pg_core.PgDateBuilder(columnName);
|
|
1528
|
+
} else if (type === "double precision") {
|
|
1529
|
+
columnBuilder = new import_pg_core.PgDoublePrecisionBuilder(columnName);
|
|
1530
|
+
} else if (type === "inet") {
|
|
1531
|
+
columnBuilder = new import_pg_core.PgInetBuilder(columnName);
|
|
1532
|
+
} else if (type === "integer") {
|
|
1533
|
+
columnBuilder = new import_pg_core.PgIntegerBuilder(columnName);
|
|
1534
|
+
} else if (type === "interval" || type.startsWith("interval ")) {
|
|
1535
|
+
columnBuilder = new import_pg_core.PgIntervalBuilder(columnName, {});
|
|
1536
|
+
} else if (type === "json") {
|
|
1537
|
+
columnBuilder = new import_pg_core.PgJsonBuilder(columnName);
|
|
1538
|
+
} else if (type === "jsonb") {
|
|
1539
|
+
columnBuilder = new import_pg_core.PgJsonbBuilder(columnName);
|
|
1540
|
+
} else if (type === "macaddr") {
|
|
1541
|
+
columnBuilder = new import_pg_core.PgMacaddrBuilder(columnName);
|
|
1542
|
+
} else if (type === "macaddr8") {
|
|
1543
|
+
columnBuilder = new import_pg_core.PgMacaddr8Builder(columnName);
|
|
1544
|
+
} else if (type === "numeric" || type.startsWith("numeric(")) {
|
|
1545
|
+
columnBuilder = new import_pg_core.PgNumericBuilder(columnName);
|
|
1546
|
+
} else if (type === "real") {
|
|
1547
|
+
columnBuilder = new import_pg_core.PgRealBuilder(columnName);
|
|
1548
|
+
} else if (type === "serial") {
|
|
1549
|
+
columnBuilder = new import_pg_core.PgSerialBuilder(columnName);
|
|
1550
|
+
} else if (type === "smallint") {
|
|
1551
|
+
columnBuilder = new import_pg_core.PgSmallIntBuilder(columnName);
|
|
1552
|
+
} else if (type === "smallserial") {
|
|
1553
|
+
columnBuilder = new import_pg_core.PgSmallSerialBuilder(columnName);
|
|
1554
|
+
} else if (type === "text") {
|
|
1555
|
+
columnBuilder = new import_pg_core.PgTextBuilder(columnName, {});
|
|
1556
|
+
} else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
|
|
1557
|
+
columnBuilder = new import_pg_core.PgTimeBuilder(columnName, false, void 0);
|
|
1558
|
+
} else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
|
|
1559
|
+
columnBuilder = new import_pg_core.PgTimestampBuilder(columnName, false, void 0);
|
|
1560
|
+
} else if (type === "uuid") {
|
|
1561
|
+
columnBuilder = new import_pg_core.PgUUIDBuilder(columnName);
|
|
1562
|
+
} else if (type === "varchar" || type.startsWith("varchar(")) {
|
|
1563
|
+
columnBuilder = new import_pg_core.PgVarcharBuilder(columnName, {});
|
|
1564
|
+
} else if (type === "char" || type.startsWith("char(")) {
|
|
1565
|
+
columnBuilder = new import_pg_core.PgCharBuilder(columnName, {});
|
|
1566
|
+
} else {
|
|
1567
|
+
columnBuilder = (0, import_pg_core.customType)({
|
|
1568
|
+
dataType() {
|
|
1569
|
+
return type;
|
|
1570
|
+
}
|
|
1571
|
+
})(columnName);
|
|
1641
1572
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
try {
|
|
1645
|
-
step(generator["throw"](value));
|
|
1646
|
-
} catch (e) {
|
|
1647
|
-
reject(e);
|
|
1573
|
+
if (c.notNull) {
|
|
1574
|
+
columnBuilder = columnBuilder.notNull();
|
|
1648
1575
|
}
|
|
1576
|
+
if (c.default) {
|
|
1577
|
+
columnBuilder = columnBuilder.default(c.default);
|
|
1578
|
+
}
|
|
1579
|
+
if (c.primaryKey) {
|
|
1580
|
+
columnBuilder = columnBuilder.primaryKey();
|
|
1581
|
+
}
|
|
1582
|
+
columns[columnName] = columnBuilder;
|
|
1583
|
+
});
|
|
1584
|
+
if (schemaName === "public") {
|
|
1585
|
+
tables[t.name] = (0, import_pg_core.pgTable)(t.name, columns, (cb) => {
|
|
1586
|
+
const res = {};
|
|
1587
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
|
1588
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
|
1589
|
+
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
|
1590
|
+
gh,
|
|
1591
|
+
cpk.name
|
|
1592
|
+
);
|
|
1593
|
+
});
|
|
1594
|
+
return res;
|
|
1595
|
+
});
|
|
1596
|
+
} else {
|
|
1597
|
+
tables[t.name] = (0, import_pg_core.pgSchema)(schemaName).table(t.name, columns, (cb) => {
|
|
1598
|
+
const res = {};
|
|
1599
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
|
1600
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
|
1601
|
+
res[cpk.name] = new import_pg_core.PrimaryKeyBuilder(
|
|
1602
|
+
gh,
|
|
1603
|
+
cpk.name
|
|
1604
|
+
);
|
|
1605
|
+
});
|
|
1606
|
+
return res;
|
|
1607
|
+
});
|
|
1649
1608
|
}
|
|
1650
|
-
function step(result) {
|
|
1651
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1652
|
-
}
|
|
1653
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1654
1609
|
});
|
|
1610
|
+
return tables;
|
|
1655
1611
|
};
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
|
|
1615
|
+
// src/serializer/sqliteSerializer.ts
|
|
1616
|
+
function mapSqlToSqliteType(sqlType) {
|
|
1617
|
+
if ([
|
|
1618
|
+
"int",
|
|
1619
|
+
"integer",
|
|
1620
|
+
"integer auto_increment",
|
|
1621
|
+
"tinyint",
|
|
1622
|
+
"smallint",
|
|
1623
|
+
"mediumint",
|
|
1624
|
+
"bigint",
|
|
1625
|
+
"unsigned big int",
|
|
1626
|
+
"int2",
|
|
1627
|
+
"int8"
|
|
1628
|
+
].includes(sqlType.toLowerCase())) {
|
|
1629
|
+
return "integer";
|
|
1630
|
+
} else if ([
|
|
1631
|
+
"character",
|
|
1632
|
+
"varchar",
|
|
1633
|
+
"vatying character",
|
|
1634
|
+
"nchar",
|
|
1635
|
+
"native character",
|
|
1636
|
+
"nvarchar",
|
|
1637
|
+
"text",
|
|
1638
|
+
"clob"
|
|
1639
|
+
].some((it) => it.startsWith(sqlType.toLowerCase()))) {
|
|
1640
|
+
return "text";
|
|
1641
|
+
} else if (sqlType.toLowerCase() === "blob") {
|
|
1642
|
+
return "blob";
|
|
1643
|
+
} else if (["real", "double", "double precision", "float"].includes(
|
|
1644
|
+
sqlType.toLowerCase()
|
|
1645
|
+
)) {
|
|
1646
|
+
return "real";
|
|
1647
|
+
} else {
|
|
1648
|
+
return "numeric";
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
var import_drizzle_orm2, import_sqlite_core, dialect2, fromDatabase2, toDrizzle2;
|
|
1652
|
+
var init_sqliteSerializer = __esm({
|
|
1653
|
+
"src/serializer/sqliteSerializer.ts"() {
|
|
1654
|
+
import_drizzle_orm2 = require("drizzle-orm");
|
|
1655
|
+
import_sqlite_core = require("drizzle-orm/sqlite-core");
|
|
1656
|
+
init_serializer();
|
|
1657
|
+
init_outputs();
|
|
1658
|
+
init_source();
|
|
1659
|
+
dialect2 = new import_sqlite_core.SQLiteSyncDialect();
|
|
1660
|
+
fromDatabase2 = async (db, tablesFilter = (table) => true, progressCallback) => {
|
|
1661
|
+
const result = {};
|
|
1662
|
+
const columns = await db.query(
|
|
1663
|
+
`SELECT
|
|
1664
|
+
m.name as "tableName", p.name as "columnName", p.type as "columnType", p."notnull" as "notNull", p.dflt_value as "defaultValue", p.pk as pk
|
|
1665
|
+
FROM sqlite_master AS m JOIN pragma_table_info(m.name) AS p
|
|
1666
|
+
WHERE m.type = 'table' and m.tbl_name != 'sqlite_sequence' and m.tbl_name != 'sqlite_stat1' and m.tbl_name != '_litestream_seq' and m.tbl_name != '_litestream_lock' and m.tbl_name != 'libsql_wasm_func_table';
|
|
1667
|
+
`
|
|
1668
|
+
);
|
|
1669
|
+
const tablesWithSeq = [];
|
|
1670
|
+
const seq = await db.query(
|
|
1671
|
+
`SELECT * FROM sqlite_master WHERE name != 'sqlite_sequence' and name != 'sqlite_stat1' and name != '_litestream_seq' and name != '_litestream_lock' and sql GLOB '*[ *' || CHAR(9) || CHAR(10) || CHAR(13) || ']AUTOINCREMENT[^'']*';`
|
|
1672
|
+
);
|
|
1673
|
+
for (const s of seq) {
|
|
1674
|
+
tablesWithSeq.push(s.name);
|
|
1707
1675
|
}
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1676
|
+
let columnsCount = 0;
|
|
1677
|
+
let tablesCount = /* @__PURE__ */ new Set();
|
|
1678
|
+
let indexesCount = 0;
|
|
1679
|
+
let foreignKeysCount = 0;
|
|
1680
|
+
const tableToPk = {};
|
|
1681
|
+
for (const column of columns) {
|
|
1682
|
+
if (!tablesFilter(column.tableName))
|
|
1683
|
+
continue;
|
|
1684
|
+
columnsCount += 1;
|
|
1685
|
+
if (progressCallback) {
|
|
1686
|
+
progressCallback("columns", columnsCount, "fetching");
|
|
1714
1687
|
}
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1688
|
+
const tableName = column.tableName;
|
|
1689
|
+
tablesCount.add(tableName);
|
|
1690
|
+
if (progressCallback) {
|
|
1691
|
+
progressCallback("tables", tablesCount.size, "fetching");
|
|
1719
1692
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
return {
|
|
1732
|
-
resolve,
|
|
1733
|
-
reject,
|
|
1734
|
-
promise
|
|
1735
|
-
};
|
|
1736
|
-
};
|
|
1737
|
-
exports.deferred = deferred;
|
|
1738
|
-
var Terminal = class {
|
|
1739
|
-
constructor(view, stdin, stdout, closable) {
|
|
1740
|
-
this.view = view;
|
|
1741
|
-
this.stdin = stdin;
|
|
1742
|
-
this.stdout = stdout;
|
|
1743
|
-
this.closable = closable;
|
|
1744
|
-
this.text = "";
|
|
1745
|
-
this.status = "idle";
|
|
1746
|
-
if (this.stdin.isTTY)
|
|
1747
|
-
this.stdin.setRawMode(true);
|
|
1748
|
-
const keypress = (str, key) => {
|
|
1749
|
-
if (key.name === "c" && key.ctrl === true) {
|
|
1750
|
-
this.requestLayout();
|
|
1751
|
-
this.view.detach(this);
|
|
1752
|
-
this.tearDown(keypress);
|
|
1753
|
-
if (terminateHandler) {
|
|
1754
|
-
terminateHandler(this.stdin, this.stdout);
|
|
1755
|
-
return;
|
|
1756
|
-
}
|
|
1757
|
-
this.stdout.write(`
|
|
1758
|
-
^C
|
|
1759
|
-
`);
|
|
1760
|
-
process.exit(1);
|
|
1761
|
-
}
|
|
1762
|
-
if (key.name === "escape") {
|
|
1763
|
-
this.status = "aborted";
|
|
1764
|
-
this.requestLayout();
|
|
1765
|
-
this.view.detach(this);
|
|
1766
|
-
this.tearDown(keypress);
|
|
1767
|
-
this.resolve({ status: "aborted", data: void 0 });
|
|
1768
|
-
return;
|
|
1769
|
-
}
|
|
1770
|
-
if (key.name === "return") {
|
|
1771
|
-
this.status = "submitted";
|
|
1772
|
-
this.requestLayout();
|
|
1773
|
-
this.view.detach(this);
|
|
1774
|
-
this.tearDown(keypress);
|
|
1775
|
-
this.resolve({ status: "submitted", data: this.view.result() });
|
|
1776
|
-
return;
|
|
1693
|
+
const columnName = column.columnName;
|
|
1694
|
+
const isNotNull = column.notNull === 1;
|
|
1695
|
+
const columnType = column.columnType;
|
|
1696
|
+
const isPrimary = column.pk !== 0;
|
|
1697
|
+
const columnDefault = column.defaultValue;
|
|
1698
|
+
const isAutoincrement = isPrimary && tablesWithSeq.includes(tableName);
|
|
1699
|
+
if (isPrimary) {
|
|
1700
|
+
if (typeof tableToPk[tableName] === "undefined") {
|
|
1701
|
+
tableToPk[tableName] = [columnName];
|
|
1702
|
+
} else {
|
|
1703
|
+
tableToPk[tableName].push(columnName);
|
|
1777
1704
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1705
|
+
}
|
|
1706
|
+
const table = result[tableName];
|
|
1707
|
+
const newColumn = {
|
|
1708
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
|
|
1709
|
+
columnDefault
|
|
1710
|
+
) ? `(${columnDefault})` : columnDefault === "false" ? false : columnDefault === "true" ? true : columnDefault.startsWith("'") && columnDefault.endsWith("'") ? columnDefault : (
|
|
1711
|
+
// ? columnDefault.substring(1, columnDefault.length - 1)
|
|
1712
|
+
`(${columnDefault})`
|
|
1713
|
+
),
|
|
1714
|
+
autoincrement: isAutoincrement,
|
|
1715
|
+
name: columnName,
|
|
1716
|
+
type: mapSqlToSqliteType(columnType),
|
|
1717
|
+
primaryKey: false,
|
|
1718
|
+
notNull: isNotNull
|
|
1719
|
+
};
|
|
1720
|
+
if (!table) {
|
|
1721
|
+
result[tableName] = {
|
|
1722
|
+
name: tableName,
|
|
1723
|
+
columns: {
|
|
1724
|
+
[columnName]: newColumn
|
|
1725
|
+
},
|
|
1726
|
+
compositePrimaryKeys: {},
|
|
1727
|
+
indexes: {},
|
|
1728
|
+
foreignKeys: {},
|
|
1729
|
+
uniqueConstraints: {}
|
|
1730
|
+
};
|
|
1802
1731
|
} else {
|
|
1803
|
-
|
|
1732
|
+
result[tableName].columns[columnName] = newColumn;
|
|
1804
1733
|
}
|
|
1805
1734
|
}
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
requestLayout() {
|
|
1820
|
-
this.terminal.requestLayout();
|
|
1821
|
-
}
|
|
1822
|
-
attach(terminal) {
|
|
1823
|
-
this.terminal = terminal;
|
|
1824
|
-
this.attachCallbacks.forEach((it) => it(terminal));
|
|
1735
|
+
for (const [key, value] of Object.entries(tableToPk)) {
|
|
1736
|
+
if (value.length > 1) {
|
|
1737
|
+
value.sort();
|
|
1738
|
+
result[key].compositePrimaryKeys = {
|
|
1739
|
+
[`${key}_${value.join("_")}_pk`]: {
|
|
1740
|
+
columns: value,
|
|
1741
|
+
name: `${key}_${value.join("_")}_pk`
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
} else if (value.length === 1) {
|
|
1745
|
+
result[key].columns[value[0]].primaryKey = true;
|
|
1746
|
+
} else {
|
|
1747
|
+
}
|
|
1825
1748
|
}
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1749
|
+
if (progressCallback) {
|
|
1750
|
+
progressCallback("columns", columnsCount, "done");
|
|
1751
|
+
progressCallback("tables", tablesCount.size, "done");
|
|
1829
1752
|
}
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1753
|
+
try {
|
|
1754
|
+
const fks = await db.query(
|
|
1755
|
+
`SELECT m.name as "tableFrom", f.id as "id", f."table" as "tableTo", f."from", f."to", f."on_update" as "onUpdate", f."on_delete" as "onDelete", f.seq as "seq"
|
|
1756
|
+
FROM sqlite_master m, pragma_foreign_key_list(m.name) as f;`
|
|
1757
|
+
);
|
|
1758
|
+
const fkByTableName = {};
|
|
1759
|
+
for (const fkRow of fks) {
|
|
1760
|
+
foreignKeysCount += 1;
|
|
1761
|
+
if (progressCallback) {
|
|
1762
|
+
progressCallback("fks", foreignKeysCount, "fetching");
|
|
1763
|
+
}
|
|
1764
|
+
const tableName = fkRow.tableFrom;
|
|
1765
|
+
const columnName = fkRow.from;
|
|
1766
|
+
const refTableName = fkRow.tableTo;
|
|
1767
|
+
const refColumnName = fkRow.to;
|
|
1768
|
+
const updateRule = fkRow.onUpdate;
|
|
1769
|
+
const deleteRule = fkRow.onDelete;
|
|
1770
|
+
const sequence = fkRow.seq;
|
|
1771
|
+
const id = fkRow.id;
|
|
1772
|
+
const tableInResult = result[tableName];
|
|
1773
|
+
if (typeof tableInResult === "undefined")
|
|
1774
|
+
continue;
|
|
1775
|
+
if (typeof fkByTableName[`${tableName}_${id}`] !== "undefined") {
|
|
1776
|
+
fkByTableName[`${tableName}_${id}`].columnsFrom.push(columnName);
|
|
1777
|
+
fkByTableName[`${tableName}_${id}`].columnsTo.push(refColumnName);
|
|
1778
|
+
} else {
|
|
1779
|
+
fkByTableName[`${tableName}_${id}`] = {
|
|
1780
|
+
name: "",
|
|
1781
|
+
tableFrom: tableName,
|
|
1782
|
+
tableTo: refTableName,
|
|
1783
|
+
columnsFrom: [columnName],
|
|
1784
|
+
columnsTo: [refColumnName],
|
|
1785
|
+
onDelete: deleteRule == null ? void 0 : deleteRule.toLowerCase(),
|
|
1786
|
+
onUpdate: updateRule == null ? void 0 : updateRule.toLowerCase()
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
const columnsFrom = fkByTableName[`${tableName}_${id}`].columnsFrom;
|
|
1790
|
+
const columnsTo = fkByTableName[`${tableName}_${id}`].columnsTo;
|
|
1791
|
+
fkByTableName[`${tableName}_${id}`].name = `${tableName}_${columnsFrom.join(
|
|
1792
|
+
"_"
|
|
1793
|
+
)}_${refTableName}_${columnsTo.join("_")}_fk`;
|
|
1835
1794
|
}
|
|
1795
|
+
for (const idx of Object.keys(fkByTableName)) {
|
|
1796
|
+
const value = fkByTableName[idx];
|
|
1797
|
+
result[value.tableFrom].foreignKeys[value.name] = value;
|
|
1798
|
+
}
|
|
1799
|
+
} catch (e) {
|
|
1836
1800
|
}
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
var TaskTerminal = class {
|
|
1840
|
-
constructor(view, stdout) {
|
|
1841
|
-
this.view = view;
|
|
1842
|
-
this.stdout = stdout;
|
|
1843
|
-
this.text = "";
|
|
1844
|
-
this.view.attach(this);
|
|
1801
|
+
if (progressCallback) {
|
|
1802
|
+
progressCallback("fks", foreignKeysCount, "done");
|
|
1845
1803
|
}
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1804
|
+
const idxs = await db.query(
|
|
1805
|
+
`SELECT
|
|
1806
|
+
m.tbl_name as tableName,
|
|
1807
|
+
il.name as indexName,
|
|
1808
|
+
ii.name as columnName,
|
|
1809
|
+
il.[unique] as isUnique,
|
|
1810
|
+
il.seq as seq
|
|
1811
|
+
FROM sqlite_master AS m,
|
|
1812
|
+
pragma_index_list(m.name) AS il,
|
|
1813
|
+
pragma_index_info(il.name) AS ii
|
|
1814
|
+
WHERE
|
|
1815
|
+
m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
|
|
1816
|
+
);
|
|
1817
|
+
for (const idxRow of idxs) {
|
|
1818
|
+
const tableName = idxRow.tableName;
|
|
1819
|
+
const constraintName = idxRow.indexName;
|
|
1820
|
+
const columnName = idxRow.columnName;
|
|
1821
|
+
const isUnique = idxRow.isUnique === 1;
|
|
1822
|
+
const tableInResult = result[tableName];
|
|
1823
|
+
if (typeof tableInResult === "undefined")
|
|
1824
|
+
continue;
|
|
1825
|
+
indexesCount += 1;
|
|
1826
|
+
if (progressCallback) {
|
|
1827
|
+
progressCallback("indexes", indexesCount, "fetching");
|
|
1828
|
+
}
|
|
1829
|
+
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
|
1830
|
+
tableInResult.indexes[constraintName].columns.push(columnName);
|
|
1831
|
+
} else {
|
|
1832
|
+
tableInResult.indexes[constraintName] = {
|
|
1833
|
+
name: constraintName,
|
|
1834
|
+
columns: [columnName],
|
|
1835
|
+
isUnique
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1851
1838
|
}
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
const clearPrefix = this.text ? (0, utils_1.clear)(this.text, this.stdout.columns) : "";
|
|
1856
|
-
this.stdout.write(`${clearPrefix}${string}`);
|
|
1839
|
+
if (progressCallback) {
|
|
1840
|
+
progressCallback("indexes", indexesCount, "done");
|
|
1841
|
+
progressCallback("enums", 0, "done");
|
|
1857
1842
|
}
|
|
1843
|
+
return {
|
|
1844
|
+
version: "5",
|
|
1845
|
+
dialect: "sqlite",
|
|
1846
|
+
tables: result,
|
|
1847
|
+
enums: {},
|
|
1848
|
+
_meta: {
|
|
1849
|
+
tables: {},
|
|
1850
|
+
columns: {}
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1858
1853
|
};
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1854
|
+
toDrizzle2 = (schema) => {
|
|
1855
|
+
const tables = {};
|
|
1856
|
+
Object.values(schema.tables).forEach((t) => {
|
|
1857
|
+
const columns = {};
|
|
1858
|
+
Object.values(t.columns).forEach((c) => {
|
|
1859
|
+
const columnName = c.name;
|
|
1860
|
+
const type = c.type;
|
|
1861
|
+
let columnBuilder;
|
|
1862
|
+
if (type === "integer") {
|
|
1863
|
+
columnBuilder = new import_sqlite_core.SQLiteIntegerBuilder(columnName);
|
|
1864
|
+
} else if (type === "text") {
|
|
1865
|
+
columnBuilder = new import_sqlite_core.SQLiteTextBuilder(columnName, {});
|
|
1866
|
+
} else if (type === "blob") {
|
|
1867
|
+
columnBuilder = new import_sqlite_core.SQLiteBlobBufferBuilder(columnName);
|
|
1868
|
+
} else if (type === "real") {
|
|
1869
|
+
columnBuilder = new import_sqlite_core.SQLiteRealBuilder(columnName);
|
|
1870
|
+
} else {
|
|
1871
|
+
columnBuilder = new import_sqlite_core.SQLiteNumericBuilder(columnName);
|
|
1872
|
+
}
|
|
1873
|
+
if (c.notNull) {
|
|
1874
|
+
columnBuilder = columnBuilder.notNull();
|
|
1875
|
+
}
|
|
1876
|
+
if (c.default) {
|
|
1877
|
+
columnBuilder = columnBuilder.default(c.default);
|
|
1878
|
+
}
|
|
1879
|
+
if (c.primaryKey) {
|
|
1880
|
+
columnBuilder = columnBuilder.primaryKey();
|
|
1881
|
+
}
|
|
1882
|
+
columns[columnName] = columnBuilder;
|
|
1883
|
+
});
|
|
1884
|
+
tables[t.name] = (0, import_sqlite_core.sqliteTable)(t.name, columns, (cb) => {
|
|
1885
|
+
const res = {};
|
|
1886
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
|
1887
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
|
1888
|
+
res[cpk.name] = new import_sqlite_core.PrimaryKeyBuilder(
|
|
1889
|
+
gh,
|
|
1890
|
+
cpk.name
|
|
1891
|
+
);
|
|
1892
|
+
});
|
|
1893
|
+
return res;
|
|
1894
|
+
});
|
|
1880
1895
|
});
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
var terminateHandler;
|
|
1884
|
-
function onTerminate(callback) {
|
|
1885
|
-
terminateHandler = callback;
|
|
1886
|
-
}
|
|
1887
|
-
exports.onTerminate = onTerminate;
|
|
1888
|
-
}
|
|
1889
|
-
});
|
|
1890
|
-
|
|
1891
|
-
// src/cli/views.ts
|
|
1892
|
-
var import_hanji;
|
|
1893
|
-
var init_views = __esm({
|
|
1894
|
-
"src/cli/views.ts"() {
|
|
1895
|
-
init_source();
|
|
1896
|
-
import_hanji = __toESM(require_hanji());
|
|
1896
|
+
return tables;
|
|
1897
|
+
};
|
|
1897
1898
|
}
|
|
1898
1899
|
});
|
|
1899
1900
|
|
|
@@ -2109,10 +2110,10 @@ var require_brace_expansion = __commonJS({
|
|
|
2109
2110
|
});
|
|
2110
2111
|
|
|
2111
2112
|
// src/drivers/index.ts
|
|
2112
|
-
var
|
|
2113
|
+
var import_drizzle_orm4, DrizzleDbClient, DrizzleORMPgClient, TursoSqlite;
|
|
2113
2114
|
var init_drivers = __esm({
|
|
2114
2115
|
"src/drivers/index.ts"() {
|
|
2115
|
-
|
|
2116
|
+
import_drizzle_orm4 = require("drizzle-orm");
|
|
2116
2117
|
DrizzleDbClient = class {
|
|
2117
2118
|
constructor(db) {
|
|
2118
2119
|
this.db = db;
|
|
@@ -2120,11 +2121,11 @@ var init_drivers = __esm({
|
|
|
2120
2121
|
};
|
|
2121
2122
|
DrizzleORMPgClient = class extends DrizzleDbClient {
|
|
2122
2123
|
async query(query, values) {
|
|
2123
|
-
const res = await this.db.execute(
|
|
2124
|
+
const res = await this.db.execute(import_drizzle_orm4.sql.raw(query));
|
|
2124
2125
|
return res.rows;
|
|
2125
2126
|
}
|
|
2126
2127
|
async run(query) {
|
|
2127
|
-
const res = await this.db.execute(
|
|
2128
|
+
const res = await this.db.execute(import_drizzle_orm4.sql.raw(query));
|
|
2128
2129
|
return res.rows;
|
|
2129
2130
|
}
|
|
2130
2131
|
};
|
|
@@ -3340,7 +3341,9 @@ var import_hanji3 = __toESM(require_hanji());
|
|
|
3340
3341
|
init_views();
|
|
3341
3342
|
init_pgSerializer();
|
|
3342
3343
|
|
|
3343
|
-
// src/introspect.ts
|
|
3344
|
+
// src/introspect-pg.ts
|
|
3345
|
+
var import_drizzle_orm3 = require("drizzle-orm");
|
|
3346
|
+
var import_relations = require("drizzle-orm/relations");
|
|
3344
3347
|
init_pgSerializer();
|
|
3345
3348
|
|
|
3346
3349
|
// src/cli/commands/pgIntrospect.ts
|