drizzle-kit 0.20.0-029419a → 0.20.0-50d6b73
Sign up to get free protection for your applications and to get access to all the features.
- package/cli/commands/sqliteIntrospect.d.ts +3 -3
- package/cli/views.d.ts +2 -2
- package/index.cjs +69 -54
- package/package.json +1 -1
- package/serializer/index.d.ts +4 -4
- package/serializer/pgSerializer.d.ts +2 -2
- package/serializer/sqliteSerializer.d.ts +2 -2
- package/sqlite-introspect.d.ts +2 -2
- package/utils-studio.d.ts +2 -0
- package/utils-studio.js +332 -15
- package/utils.js +46 -45
@@ -1,7 +1,7 @@
|
|
1
|
-
import { SQLiteCliConfig, SQLiteConnectionConfig } from "./sqliteUtils";
|
2
|
-
import {
|
1
|
+
import type { SQLiteCliConfig, SQLiteConnectionConfig } from "./sqliteUtils";
|
2
|
+
import type { DrizzleDbClient } from "../../drivers";
|
3
3
|
export declare const connectToSQLite: (config: SQLiteConnectionConfig) => Promise<{
|
4
|
-
client: BetterSqlite;
|
4
|
+
client: import("../../drivers").BetterSqlite;
|
5
5
|
} | {
|
6
6
|
client?: undefined;
|
7
7
|
}>;
|
package/cli/views.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Prompt, TaskView } from "hanji";
|
2
|
-
import { CommonSchema } from "src/schemaValidator";
|
3
|
-
import { Named } from "./commands/migrate";
|
2
|
+
import type { CommonSchema } from "src/schemaValidator";
|
3
|
+
import type { Named } from "./commands/migrate";
|
4
4
|
export declare const warning: (msg: string) => void;
|
5
5
|
export declare const err: (msg: string) => void;
|
6
6
|
export declare const info: (msg: string, greyMsg?: string) => string;
|
package/index.cjs
CHANGED
@@ -12091,13 +12091,12 @@ __export(pgSerializer_exports, {
|
|
12091
12091
|
indexName: () => indexName2,
|
12092
12092
|
toDrizzle: () => toDrizzle
|
12093
12093
|
});
|
12094
|
-
var import_pg_core2, import_pg_core3, import_drizzle_orm5,
|
12094
|
+
var import_pg_core2, import_pg_core3, import_drizzle_orm5, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn, toDrizzle;
|
12095
12095
|
var init_pgSerializer = __esm({
|
12096
12096
|
"src/serializer/pgSerializer.ts"() {
|
12097
12097
|
import_pg_core2 = require("drizzle-orm/pg-core");
|
12098
12098
|
import_pg_core3 = require("drizzle-orm/pg-core");
|
12099
12099
|
import_drizzle_orm5 = require("drizzle-orm");
|
12100
|
-
import_drizzle_orm6 = require("drizzle-orm");
|
12101
12100
|
init_serializer();
|
12102
12101
|
init_source();
|
12103
12102
|
init_outputs();
|
@@ -12228,7 +12227,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12228
12227
|
const onDelete = fk4.onDelete;
|
12229
12228
|
const onUpdate = fk4.onUpdate;
|
12230
12229
|
const reference = fk4.reference();
|
12231
|
-
const tableTo = (0,
|
12230
|
+
const tableTo = (0, import_drizzle_orm5.getTableName)(reference.foreignTable);
|
12232
12231
|
const columnsFrom = reference.columns.map((it) => it.name);
|
12233
12232
|
const columnsTo = reference.foreignColumns.map((it) => it.name);
|
12234
12233
|
return {
|
@@ -12798,11 +12797,11 @@ var sqliteImports_exports = {};
|
|
12798
12797
|
__export(sqliteImports_exports, {
|
12799
12798
|
prepareFromSqliteImports: () => prepareFromSqliteImports
|
12800
12799
|
});
|
12801
|
-
var import_sqlite_core,
|
12800
|
+
var import_sqlite_core, import_drizzle_orm6, prepareFromSqliteImports;
|
12802
12801
|
var init_sqliteImports = __esm({
|
12803
12802
|
"src/serializer/sqliteImports.ts"() {
|
12804
12803
|
import_sqlite_core = require("drizzle-orm/sqlite-core");
|
12805
|
-
|
12804
|
+
import_drizzle_orm6 = require("drizzle-orm");
|
12806
12805
|
init_utils();
|
12807
12806
|
prepareFromSqliteImports = async (imports) => {
|
12808
12807
|
const tables = [];
|
@@ -12813,7 +12812,7 @@ var init_sqliteImports = __esm({
|
|
12813
12812
|
const i0 = require(`${it}`);
|
12814
12813
|
const i0values = Object.values(i0);
|
12815
12814
|
i0values.forEach((t) => {
|
12816
|
-
if ((0,
|
12815
|
+
if ((0, import_drizzle_orm6.is)(t, import_sqlite_core.SQLiteTable)) {
|
12817
12816
|
tables.push(t);
|
12818
12817
|
}
|
12819
12818
|
});
|
@@ -12866,11 +12865,10 @@ function mapSqlToSqliteType(sqlType) {
|
|
12866
12865
|
return "numeric";
|
12867
12866
|
}
|
12868
12867
|
}
|
12869
|
-
var
|
12868
|
+
var import_drizzle_orm7, import_sqlite_core2, dialect5, generateSqliteSnapshot, fromDatabase3, toDrizzle2;
|
12870
12869
|
var init_sqliteSerializer = __esm({
|
12871
12870
|
"src/serializer/sqliteSerializer.ts"() {
|
12872
|
-
|
12873
|
-
import_drizzle_orm9 = require("drizzle-orm");
|
12871
|
+
import_drizzle_orm7 = require("drizzle-orm");
|
12874
12872
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
12875
12873
|
init_serializer();
|
12876
12874
|
init_outputs();
|
@@ -12900,10 +12898,10 @@ var init_sqliteSerializer = __esm({
|
|
12900
12898
|
type: column7.getSQLType(),
|
12901
12899
|
primaryKey,
|
12902
12900
|
notNull,
|
12903
|
-
autoincrement: (0,
|
12901
|
+
autoincrement: (0, import_drizzle_orm7.is)(column7, import_sqlite_core2.SQLiteBaseInteger) ? column7.autoIncrement : false
|
12904
12902
|
};
|
12905
12903
|
if (column7.default !== void 0) {
|
12906
|
-
if ((0,
|
12904
|
+
if ((0, import_drizzle_orm7.is)(column7.default, import_drizzle_orm7.SQL)) {
|
12907
12905
|
columnToSet.default = sqlToStr(column7.default);
|
12908
12906
|
} else {
|
12909
12907
|
columnToSet.default = typeof column7.default === "string" ? `'${column7.default}'` : column7.default;
|
@@ -12943,7 +12941,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12943
12941
|
const onUpdate = fk4.onUpdate ?? "no action";
|
12944
12942
|
const reference = fk4.reference();
|
12945
12943
|
const referenceFT = reference.foreignTable;
|
12946
|
-
const tableTo = (0,
|
12944
|
+
const tableTo = (0, import_drizzle_orm7.getTableName)(referenceFT);
|
12947
12945
|
const columnsFrom = reference.columns.map((it) => it.name);
|
12948
12946
|
const columnsTo = reference.foreignColumns.map((it) => it.name);
|
12949
12947
|
return {
|
@@ -12963,7 +12961,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12963
12961
|
const columns2 = value.config.columns;
|
12964
12962
|
const name = value.config.name;
|
12965
12963
|
let indexColumns = columns2.map((it) => {
|
12966
|
-
if ((0,
|
12964
|
+
if ((0, import_drizzle_orm7.is)(it, import_drizzle_orm7.SQL)) {
|
12967
12965
|
return dialect5.sqlToQuery(it).sql;
|
12968
12966
|
} else {
|
12969
12967
|
return it.name;
|
@@ -12971,7 +12969,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12971
12969
|
});
|
12972
12970
|
let where = void 0;
|
12973
12971
|
if (value.config.where !== void 0) {
|
12974
|
-
if ((0,
|
12972
|
+
if ((0, import_drizzle_orm7.is)(value.config.where, import_drizzle_orm7.SQL)) {
|
12975
12973
|
where = dialect5.sqlToQuery(value.config.where).sql;
|
12976
12974
|
}
|
12977
12975
|
}
|
@@ -13269,7 +13267,10 @@ WHERE
|
|
13269
13267
|
const res = {};
|
13270
13268
|
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
13271
13269
|
const gh = cpk.columns.map((c) => cb[c]);
|
13272
|
-
res[cpk.name] = new import_sqlite_core2.PrimaryKeyBuilder(
|
13270
|
+
res[cpk.name] = new import_sqlite_core2.PrimaryKeyBuilder(
|
13271
|
+
gh,
|
13272
|
+
cpk.name
|
13273
|
+
);
|
13273
13274
|
});
|
13274
13275
|
return res;
|
13275
13276
|
});
|
@@ -13289,13 +13290,13 @@ var init_serializer = __esm({
|
|
13289
13290
|
init_source();
|
13290
13291
|
sqlToStr = (sql2) => {
|
13291
13292
|
return sql2.toQuery({
|
13292
|
-
escapeName: (
|
13293
|
+
escapeName: () => {
|
13293
13294
|
throw new Error("we don't support params for `sql` default values");
|
13294
13295
|
},
|
13295
|
-
escapeParam: (
|
13296
|
+
escapeParam: () => {
|
13296
13297
|
throw new Error("we don't support params for `sql` default values");
|
13297
13298
|
},
|
13298
|
-
escapeString: (
|
13299
|
+
escapeString: () => {
|
13299
13300
|
throw new Error("we don't support params for `sql` default values");
|
13300
13301
|
}
|
13301
13302
|
}).sql;
|
@@ -25178,15 +25179,33 @@ var require_lib2 = __commonJS({
|
|
25178
25179
|
});
|
25179
25180
|
|
25180
25181
|
// src/drivers/index.ts
|
25181
|
-
var
|
25182
|
+
var drivers_exports = {};
|
25183
|
+
__export(drivers_exports, {
|
25184
|
+
BetterSqlite: () => BetterSqlite,
|
25185
|
+
DrizzleDbClient: () => DrizzleDbClient,
|
25186
|
+
DrizzleORMPgClient: () => DrizzleORMPgClient,
|
25187
|
+
PgPostgres: () => PgPostgres,
|
25188
|
+
TursoSqlite: () => TursoSqlite
|
25189
|
+
});
|
25190
|
+
var import_drizzle_orm8, DrizzleDbClient, DrizzleORMPgClient, BetterSqlite, TursoSqlite, PgPostgres;
|
25182
25191
|
var init_drivers = __esm({
|
25183
25192
|
"src/drivers/index.ts"() {
|
25184
|
-
|
25193
|
+
import_drizzle_orm8 = require("drizzle-orm");
|
25185
25194
|
DrizzleDbClient = class {
|
25186
25195
|
constructor(db) {
|
25187
25196
|
this.db = db;
|
25188
25197
|
}
|
25189
25198
|
};
|
25199
|
+
DrizzleORMPgClient = class extends DrizzleDbClient {
|
25200
|
+
async query(query, values) {
|
25201
|
+
const res = await this.db.execute(import_drizzle_orm8.sql.raw(query));
|
25202
|
+
return res.rows;
|
25203
|
+
}
|
25204
|
+
async run(query) {
|
25205
|
+
const res = await this.db.execute(import_drizzle_orm8.sql.raw(query));
|
25206
|
+
return res.rows;
|
25207
|
+
}
|
25208
|
+
};
|
25190
25209
|
BetterSqlite = class extends DrizzleDbClient {
|
25191
25210
|
async run(query) {
|
25192
25211
|
this.db.prepare(query).run();
|
@@ -25871,18 +25890,18 @@ var init_sqliteIntrospect = __esm({
|
|
25871
25890
|
init_sqlite_introspect();
|
25872
25891
|
init_mjs();
|
25873
25892
|
import_hanji7 = __toESM(require_hanji());
|
25874
|
-
init_drivers();
|
25875
25893
|
connectToSQLite = async (config) => {
|
25894
|
+
const { BetterSqlite: BetterSqlite2, TursoSqlite: TursoSqlite2 } = await Promise.resolve().then(() => (init_drivers(), drivers_exports));
|
25876
25895
|
if (config.driver === "better-sqlite") {
|
25877
25896
|
const { default: Database } = await import("better-sqlite3");
|
25878
25897
|
return {
|
25879
|
-
client: new
|
25898
|
+
client: new BetterSqlite2(new Database(config.dbCredentials.url))
|
25880
25899
|
};
|
25881
25900
|
}
|
25882
25901
|
if (config.driver === "libsql") {
|
25883
25902
|
const { createClient } = await import("@libsql/client");
|
25884
25903
|
return {
|
25885
|
-
client: new
|
25904
|
+
client: new TursoSqlite2(
|
25886
25905
|
createClient({
|
25887
25906
|
url: config.dbCredentials.url
|
25888
25907
|
})
|
@@ -25891,7 +25910,7 @@ var init_sqliteIntrospect = __esm({
|
|
25891
25910
|
} else {
|
25892
25911
|
const { createClient } = await import("@libsql/client");
|
25893
25912
|
return {
|
25894
|
-
client: new
|
25913
|
+
client: new TursoSqlite2(
|
25895
25914
|
createClient({
|
25896
25915
|
url: config.dbCredentials.url,
|
25897
25916
|
authToken: config.dbCredentials.authToken
|
@@ -25919,13 +25938,9 @@ var init_sqliteIntrospect = __esm({
|
|
25919
25938
|
const progress = new IntrospectProgress();
|
25920
25939
|
const res = await (0, import_hanji7.renderWithTask)(
|
25921
25940
|
progress,
|
25922
|
-
fromDatabase3(
|
25923
|
-
|
25924
|
-
|
25925
|
-
(stage, count, status) => {
|
25926
|
-
progress.update(stage, count, status);
|
25927
|
-
}
|
25928
|
-
)
|
25941
|
+
fromDatabase3(client, filter2, (stage, count, status) => {
|
25942
|
+
progress.update(stage, count, status);
|
25943
|
+
})
|
25929
25944
|
);
|
25930
25945
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
25931
25946
|
const ts = schemaToTypeScript2(schema4, config.introspect.casing);
|
@@ -42507,14 +42522,14 @@ var require_promise = __commonJS({
|
|
42507
42522
|
});
|
42508
42523
|
|
42509
42524
|
// src/orm-extenstions/d1-driver/session.ts
|
42510
|
-
var
|
42525
|
+
var import_drizzle_orm9, import_drizzle_orm10, import_drizzle_orm11, import_sqlite_core3, import_drizzle_orm12, _a, SQLiteWranglerD1Session, _a2, PreparedQuery;
|
42511
42526
|
var init_session = __esm({
|
42512
42527
|
"src/orm-extenstions/d1-driver/session.ts"() {
|
42528
|
+
import_drizzle_orm9 = require("drizzle-orm");
|
42529
|
+
import_drizzle_orm10 = require("drizzle-orm");
|
42513
42530
|
import_drizzle_orm11 = require("drizzle-orm");
|
42514
|
-
import_drizzle_orm12 = require("drizzle-orm");
|
42515
|
-
import_drizzle_orm13 = require("drizzle-orm");
|
42516
42531
|
import_sqlite_core3 = require("drizzle-orm/sqlite-core");
|
42517
|
-
|
42532
|
+
import_drizzle_orm12 = require("drizzle-orm");
|
42518
42533
|
SQLiteWranglerD1Session = class extends import_sqlite_core3.SQLiteSession {
|
42519
42534
|
constructor(client, configPath, dbName, dialect6, schema4, options = {}) {
|
42520
42535
|
super(dialect6);
|
@@ -42523,7 +42538,7 @@ var init_session = __esm({
|
|
42523
42538
|
this.dbName = dbName;
|
42524
42539
|
this.schema = schema4;
|
42525
42540
|
this.options = options;
|
42526
|
-
this.logger = options.logger ?? new
|
42541
|
+
this.logger = options.logger ?? new import_drizzle_orm10.NoopLogger();
|
42527
42542
|
}
|
42528
42543
|
prepareQuery(query, fields, executeMethod, customResultMapper) {
|
42529
42544
|
return new PreparedQuery(
|
@@ -42542,7 +42557,7 @@ var init_session = __esm({
|
|
42542
42557
|
throw new Error("no transaction support yet");
|
42543
42558
|
}
|
42544
42559
|
};
|
42545
|
-
_a =
|
42560
|
+
_a = import_drizzle_orm9.entityKind;
|
42546
42561
|
SQLiteWranglerD1Session[_a] = "SQLiteD1Session";
|
42547
42562
|
PreparedQuery = class extends import_sqlite_core3.PreparedQuery {
|
42548
42563
|
constructor(stmt, configPath, dbName, queryString, params, logger, fields, executeMethod, customResultMapper) {
|
@@ -42557,14 +42572,14 @@ var init_session = __esm({
|
|
42557
42572
|
this.customResultMapper = customResultMapper;
|
42558
42573
|
}
|
42559
42574
|
run(placeholderValues) {
|
42560
|
-
const params = (0,
|
42575
|
+
const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
|
42561
42576
|
this.logger.logQuery(this.queryString, params);
|
42562
42577
|
return this.stmt(this.queryString, this.configPath, this.dbName);
|
42563
42578
|
}
|
42564
42579
|
async all(placeholderValues) {
|
42565
42580
|
const { fields, queryString, logger, stmt, customResultMapper } = this;
|
42566
42581
|
if (!fields && !customResultMapper) {
|
42567
|
-
const params = (0,
|
42582
|
+
const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
|
42568
42583
|
logger.logQuery(queryString, params);
|
42569
42584
|
return stmt(this.queryString, this.configPath, this.dbName).then(
|
42570
42585
|
({ results }) => results
|
@@ -42574,12 +42589,12 @@ var init_session = __esm({
|
|
42574
42589
|
if (customResultMapper) {
|
42575
42590
|
return customResultMapper(rows);
|
42576
42591
|
}
|
42577
|
-
return rows.map((row) => (0,
|
42592
|
+
return rows.map((row) => (0, import_drizzle_orm12.mapResultRow)(fields, row, void 0));
|
42578
42593
|
}
|
42579
42594
|
async get(placeholderValues) {
|
42580
42595
|
const { fields, queryString, logger, stmt, customResultMapper } = this;
|
42581
42596
|
if (!fields && !customResultMapper) {
|
42582
|
-
const params = (0,
|
42597
|
+
const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
|
42583
42598
|
logger.logQuery(queryString, params);
|
42584
42599
|
return stmt(queryString, this.configPath, this.dbName).then(
|
42585
42600
|
({ results }) => results[0]
|
@@ -42603,13 +42618,13 @@ var init_session = __esm({
|
|
42603
42618
|
return rows;
|
42604
42619
|
}
|
42605
42620
|
async values(placeholderValues) {
|
42606
|
-
const params = (0,
|
42621
|
+
const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
|
42607
42622
|
this.logger.logQuery(this.queryString, params);
|
42608
42623
|
const wranglerRes = await this.stmt(this.queryString, this.configPath, this.dbName);
|
42609
42624
|
return this.d1ToRawMapping(wranglerRes.results);
|
42610
42625
|
}
|
42611
42626
|
};
|
42612
|
-
_a2 =
|
42627
|
+
_a2 = import_drizzle_orm9.entityKind;
|
42613
42628
|
PreparedQuery[_a2] = "D1PreparedQuery";
|
42614
42629
|
}
|
42615
42630
|
});
|
@@ -42643,15 +42658,15 @@ function drizzle(client, configPath, dbName, config = {}) {
|
|
42643
42658
|
const dialect6 = new WranglerDialect();
|
42644
42659
|
let logger;
|
42645
42660
|
if (config.logger === true) {
|
42646
|
-
logger = new
|
42661
|
+
logger = new import_drizzle_orm13.DefaultLogger();
|
42647
42662
|
} else if (config.logger !== false) {
|
42648
42663
|
logger = config.logger;
|
42649
42664
|
}
|
42650
42665
|
let schema4;
|
42651
42666
|
if (config.schema) {
|
42652
|
-
const tablesConfig = (0,
|
42667
|
+
const tablesConfig = (0, import_drizzle_orm13.extractTablesRelationalConfig)(
|
42653
42668
|
config.schema,
|
42654
|
-
|
42669
|
+
import_drizzle_orm13.createTableRelationsHelpers
|
42655
42670
|
);
|
42656
42671
|
schema4 = {
|
42657
42672
|
fullSchema: config.schema,
|
@@ -42669,10 +42684,10 @@ function drizzle(client, configPath, dbName, config = {}) {
|
|
42669
42684
|
schema4
|
42670
42685
|
);
|
42671
42686
|
}
|
42672
|
-
var
|
42687
|
+
var import_drizzle_orm13, import_sqlite_core4, WranglerDialect;
|
42673
42688
|
var init_driver = __esm({
|
42674
42689
|
"src/orm-extenstions/d1-driver/driver.ts"() {
|
42675
|
-
|
42690
|
+
import_drizzle_orm13 = require("drizzle-orm");
|
42676
42691
|
import_sqlite_core4 = require("drizzle-orm/sqlite-core");
|
42677
42692
|
init_session();
|
42678
42693
|
WranglerDialect = class extends import_sqlite_core4.SQLiteAsyncDialect {
|
@@ -57987,10 +58002,10 @@ __export(studioUtils_exports, {
|
|
57987
58002
|
drizzleDb: () => drizzleDb,
|
57988
58003
|
prepareModels: () => prepareModels
|
57989
58004
|
});
|
57990
|
-
var
|
58005
|
+
var import_drizzle_orm14, import_mysql_core4, import_pg_core4, import_sqlite_core5, prepareModels, drizzleDb;
|
57991
58006
|
var init_studioUtils = __esm({
|
57992
58007
|
"src/serializer/studioUtils.ts"() {
|
57993
|
-
|
58008
|
+
import_drizzle_orm14 = require("drizzle-orm");
|
57994
58009
|
import_mysql_core4 = require("drizzle-orm/mysql-core");
|
57995
58010
|
import_pg_core4 = require("drizzle-orm/pg-core");
|
57996
58011
|
import_sqlite_core5 = require("drizzle-orm/sqlite-core");
|
@@ -58007,16 +58022,16 @@ var init_studioUtils = __esm({
|
|
58007
58022
|
const i0 = require(`${it}`);
|
58008
58023
|
const i0values = Object.entries(i0);
|
58009
58024
|
i0values.forEach(([k, t]) => {
|
58010
|
-
if ((0,
|
58025
|
+
if ((0, import_drizzle_orm14.is)(t, import_pg_core4.PgTable)) {
|
58011
58026
|
pgSchema3[k] = t;
|
58012
58027
|
}
|
58013
|
-
if ((0,
|
58028
|
+
if ((0, import_drizzle_orm14.is)(t, import_mysql_core4.MySqlTable)) {
|
58014
58029
|
mysqlSchema4[k] = t;
|
58015
58030
|
}
|
58016
|
-
if ((0,
|
58031
|
+
if ((0, import_drizzle_orm14.is)(t, import_sqlite_core5.SQLiteTable)) {
|
58017
58032
|
sqliteSchema2[k] = t;
|
58018
58033
|
}
|
58019
|
-
if ((0,
|
58034
|
+
if ((0, import_drizzle_orm14.is)(t, import_drizzle_orm14.Relations)) {
|
58020
58035
|
sqliteSchema2[k] = t;
|
58021
58036
|
pgSchema3[k] = t;
|
58022
58037
|
mysqlSchema4[k] = t;
|
package/package.json
CHANGED
package/serializer/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { PgSchemaInternal } from "./pgSchema";
|
2
|
-
import { SQLiteSchemaInternal } from "./sqliteSchema";
|
3
|
-
import { MySqlSchemaInternal } from "./mysqlSchema";
|
4
|
-
import { SQL } from "drizzle-orm";
|
1
|
+
import type { PgSchemaInternal } from "./pgSchema";
|
2
|
+
import type { SQLiteSchemaInternal } from "./sqliteSchema";
|
3
|
+
import type { MySqlSchemaInternal } from "./mysqlSchema";
|
4
|
+
import type { SQL } from "drizzle-orm";
|
5
5
|
export declare const sqlToStr: (sql: SQL) => string;
|
6
6
|
export declare const serializeMySql: (path: string | string[]) => Promise<MySqlSchemaInternal>;
|
7
7
|
export declare const serializePg: (path: string | string[], schemaFilter?: string[]) => Promise<PgSchemaInternal>;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { AnyPgTable, PgEnum, PgSchema } from "drizzle-orm/pg-core";
|
2
2
|
import { Relations } from "drizzle-orm";
|
3
|
-
import { IntrospectStage, IntrospectStatus } from "src/cli/views";
|
4
|
-
import { PgSchemaInternal } from "src/serializer/pgSchema";
|
3
|
+
import type { IntrospectStage, IntrospectStatus } from "src/cli/views";
|
4
|
+
import type { PgSchemaInternal } from "src/serializer/pgSchema";
|
5
5
|
import type { DrizzleDbClient } from "src/drivers";
|
6
6
|
export declare const indexName: (tableName: string, columns: string[]) => string;
|
7
7
|
export declare const generatePgSnapshot: (tables: AnyPgTable[], enums: PgEnum<any>[], schemas: PgSchema[], schemaFilter?: string[]) => PgSchemaInternal;
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { SQLiteSchemaInternal } from "
|
1
|
+
import type { SQLiteSchemaInternal } from "../serializer/sqliteSchema";
|
2
2
|
import { Relations } from "drizzle-orm";
|
3
3
|
import { AnySQLiteTable } from "drizzle-orm/sqlite-core";
|
4
|
-
import { IntrospectStage, IntrospectStatus } from "src/cli/views";
|
4
|
+
import type { IntrospectStage, IntrospectStatus } from "src/cli/views";
|
5
5
|
import type { DrizzleDbClient } from "src/drivers";
|
6
6
|
export declare const generateSqliteSnapshot: (tables: AnySQLiteTable[], enums: any[]) => SQLiteSchemaInternal;
|
7
7
|
export declare const fromDatabase: (db: DrizzleDbClient, tablesFilter?: (table: string) => boolean, progressCallback?: ((stage: IntrospectStage, count: number, status: IntrospectStatus) => void) | undefined) => Promise<SQLiteSchemaInternal>;
|
package/sqlite-introspect.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import "./@types/utils";
|
2
|
-
import { ConfigIntrospectCasing } from "./cli/commands/utils";
|
3
|
-
import { SQLiteSchema } from "./serializer/sqliteSchema";
|
2
|
+
import type { ConfigIntrospectCasing } from "./cli/commands/utils";
|
3
|
+
import type { SQLiteSchema } from "./serializer/sqliteSchema";
|
4
4
|
export declare const indexName: (tableName: string, columns: string[]) => string;
|
5
5
|
export declare const schemaToTypeScript: (schema: SQLiteSchema, casing: ConfigIntrospectCasing["casing"]) => string;
|
package/utils-studio.d.ts
CHANGED
@@ -1,2 +1,4 @@
|
|
1
1
|
export { toDrizzle as drizzleSchemaPg } from "./serializer/pgSerializer";
|
2
|
+
export { toDrizzle as drizzleSchemaSQLite } from "./serializer/sqliteSerializer";
|
3
|
+
export { sqlitePushIntrospect } from "./cli/commands/sqliteIntrospect";
|
2
4
|
export { pgPushIntrospect } from "./cli/commands/pgIntrospect";
|
package/utils-studio.js
CHANGED
@@ -560,13 +560,12 @@ var init_outputs = __esm({
|
|
560
560
|
});
|
561
561
|
|
562
562
|
// src/serializer/pgSerializer.ts
|
563
|
-
var import_pg_core, import_pg_core2, import_drizzle_orm,
|
563
|
+
var import_pg_core, import_pg_core2, import_drizzle_orm, dialect, trimChar, fromDatabase, columnToDefault, defaultForColumn, toDrizzle;
|
564
564
|
var init_pgSerializer = __esm({
|
565
565
|
"src/serializer/pgSerializer.ts"() {
|
566
566
|
import_pg_core = require("drizzle-orm/pg-core");
|
567
567
|
import_pg_core2 = require("drizzle-orm/pg-core");
|
568
568
|
import_drizzle_orm = require("drizzle-orm");
|
569
|
-
import_drizzle_orm2 = require("drizzle-orm");
|
570
569
|
init_serializer();
|
571
570
|
init_source();
|
572
571
|
init_outputs();
|
@@ -1059,6 +1058,292 @@ var init_pgSerializer = __esm({
|
|
1059
1058
|
}
|
1060
1059
|
});
|
1061
1060
|
|
1061
|
+
// src/serializer/sqliteSerializer.ts
|
1062
|
+
function mapSqlToSqliteType(sqlType) {
|
1063
|
+
if ([
|
1064
|
+
"int",
|
1065
|
+
"integer",
|
1066
|
+
"integer auto_increment",
|
1067
|
+
"tinyint",
|
1068
|
+
"smallint",
|
1069
|
+
"mediumint",
|
1070
|
+
"bigint",
|
1071
|
+
"unsigned big int",
|
1072
|
+
"int2",
|
1073
|
+
"int8"
|
1074
|
+
].includes(sqlType.toLowerCase())) {
|
1075
|
+
return "integer";
|
1076
|
+
} else if ([
|
1077
|
+
"character",
|
1078
|
+
"varchar",
|
1079
|
+
"vatying character",
|
1080
|
+
"nchar",
|
1081
|
+
"native character",
|
1082
|
+
"nvarchar",
|
1083
|
+
"text",
|
1084
|
+
"clob"
|
1085
|
+
].some((it) => it.startsWith(sqlType.toLowerCase()))) {
|
1086
|
+
return "text";
|
1087
|
+
} else if (sqlType.toLowerCase() === "blob") {
|
1088
|
+
return "blob";
|
1089
|
+
} else if (["real", "double", "double precision", "float"].includes(
|
1090
|
+
sqlType.toLowerCase()
|
1091
|
+
)) {
|
1092
|
+
return "real";
|
1093
|
+
} else {
|
1094
|
+
return "numeric";
|
1095
|
+
}
|
1096
|
+
}
|
1097
|
+
var import_drizzle_orm2, import_sqlite_core, dialect2, fromDatabase2, toDrizzle2;
|
1098
|
+
var init_sqliteSerializer = __esm({
|
1099
|
+
"src/serializer/sqliteSerializer.ts"() {
|
1100
|
+
import_drizzle_orm2 = require("drizzle-orm");
|
1101
|
+
import_sqlite_core = require("drizzle-orm/sqlite-core");
|
1102
|
+
init_serializer();
|
1103
|
+
init_outputs();
|
1104
|
+
init_source();
|
1105
|
+
dialect2 = new import_sqlite_core.SQLiteSyncDialect();
|
1106
|
+
fromDatabase2 = async (db, tablesFilter = (table) => true, progressCallback) => {
|
1107
|
+
const result = {};
|
1108
|
+
const columns = await db.query(
|
1109
|
+
`SELECT
|
1110
|
+
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
|
1111
|
+
FROM sqlite_master AS m JOIN pragma_table_info(m.name) AS p
|
1112
|
+
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';
|
1113
|
+
`
|
1114
|
+
);
|
1115
|
+
const tablesWithSeq = [];
|
1116
|
+
const seq = await db.query(
|
1117
|
+
`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[^'']*';`
|
1118
|
+
);
|
1119
|
+
for (const s of seq) {
|
1120
|
+
tablesWithSeq.push(s.name);
|
1121
|
+
}
|
1122
|
+
let columnsCount = 0;
|
1123
|
+
let tablesCount = /* @__PURE__ */ new Set();
|
1124
|
+
let indexesCount = 0;
|
1125
|
+
let foreignKeysCount = 0;
|
1126
|
+
const tableToPk = {};
|
1127
|
+
for (const column of columns) {
|
1128
|
+
if (!tablesFilter(column.tableName))
|
1129
|
+
continue;
|
1130
|
+
columnsCount += 1;
|
1131
|
+
if (progressCallback) {
|
1132
|
+
progressCallback("columns", columnsCount, "fetching");
|
1133
|
+
}
|
1134
|
+
const tableName = column.tableName;
|
1135
|
+
tablesCount.add(tableName);
|
1136
|
+
if (progressCallback) {
|
1137
|
+
progressCallback("tables", tablesCount.size, "fetching");
|
1138
|
+
}
|
1139
|
+
const columnName = column.columnName;
|
1140
|
+
const isNotNull = column.notNull === 1;
|
1141
|
+
const columnType = column.columnType;
|
1142
|
+
const isPrimary = column.pk !== 0;
|
1143
|
+
const columnDefault = column.defaultValue;
|
1144
|
+
const isAutoincrement = isPrimary && tablesWithSeq.includes(tableName);
|
1145
|
+
if (isPrimary) {
|
1146
|
+
if (typeof tableToPk[tableName] === "undefined") {
|
1147
|
+
tableToPk[tableName] = [columnName];
|
1148
|
+
} else {
|
1149
|
+
tableToPk[tableName].push(columnName);
|
1150
|
+
}
|
1151
|
+
}
|
1152
|
+
const table = result[tableName];
|
1153
|
+
const newColumn = {
|
1154
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
|
1155
|
+
columnDefault
|
1156
|
+
) ? `(${columnDefault})` : columnDefault === "false" ? false : columnDefault === "true" ? true : columnDefault.startsWith("'") && columnDefault.endsWith("'") ? columnDefault : (
|
1157
|
+
// ? columnDefault.substring(1, columnDefault.length - 1)
|
1158
|
+
`(${columnDefault})`
|
1159
|
+
),
|
1160
|
+
autoincrement: isAutoincrement,
|
1161
|
+
name: columnName,
|
1162
|
+
type: mapSqlToSqliteType(columnType),
|
1163
|
+
primaryKey: false,
|
1164
|
+
notNull: isNotNull
|
1165
|
+
};
|
1166
|
+
if (!table) {
|
1167
|
+
result[tableName] = {
|
1168
|
+
name: tableName,
|
1169
|
+
columns: {
|
1170
|
+
[columnName]: newColumn
|
1171
|
+
},
|
1172
|
+
compositePrimaryKeys: {},
|
1173
|
+
indexes: {},
|
1174
|
+
foreignKeys: {},
|
1175
|
+
uniqueConstraints: {}
|
1176
|
+
};
|
1177
|
+
} else {
|
1178
|
+
result[tableName].columns[columnName] = newColumn;
|
1179
|
+
}
|
1180
|
+
}
|
1181
|
+
for (const [key, value] of Object.entries(tableToPk)) {
|
1182
|
+
if (value.length > 1) {
|
1183
|
+
value.sort();
|
1184
|
+
result[key].compositePrimaryKeys = {
|
1185
|
+
[`${key}_${value.join("_")}_pk`]: {
|
1186
|
+
columns: value,
|
1187
|
+
name: `${key}_${value.join("_")}_pk`
|
1188
|
+
}
|
1189
|
+
};
|
1190
|
+
} else if (value.length === 1) {
|
1191
|
+
result[key].columns[value[0]].primaryKey = true;
|
1192
|
+
} else {
|
1193
|
+
}
|
1194
|
+
}
|
1195
|
+
if (progressCallback) {
|
1196
|
+
progressCallback("columns", columnsCount, "done");
|
1197
|
+
progressCallback("tables", tablesCount.size, "done");
|
1198
|
+
}
|
1199
|
+
try {
|
1200
|
+
const fks = await db.query(
|
1201
|
+
`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"
|
1202
|
+
FROM sqlite_master m, pragma_foreign_key_list(m.name) as f;`
|
1203
|
+
);
|
1204
|
+
const fkByTableName = {};
|
1205
|
+
for (const fkRow of fks) {
|
1206
|
+
foreignKeysCount += 1;
|
1207
|
+
if (progressCallback) {
|
1208
|
+
progressCallback("fks", foreignKeysCount, "fetching");
|
1209
|
+
}
|
1210
|
+
const tableName = fkRow.tableFrom;
|
1211
|
+
const columnName = fkRow.from;
|
1212
|
+
const refTableName = fkRow.tableTo;
|
1213
|
+
const refColumnName = fkRow.to;
|
1214
|
+
const updateRule = fkRow.onUpdate;
|
1215
|
+
const deleteRule = fkRow.onDelete;
|
1216
|
+
const sequence = fkRow.seq;
|
1217
|
+
const id = fkRow.id;
|
1218
|
+
const tableInResult = result[tableName];
|
1219
|
+
if (typeof tableInResult === "undefined")
|
1220
|
+
continue;
|
1221
|
+
if (typeof fkByTableName[`${tableName}_${id}`] !== "undefined") {
|
1222
|
+
fkByTableName[`${tableName}_${id}`].columnsFrom.push(columnName);
|
1223
|
+
fkByTableName[`${tableName}_${id}`].columnsTo.push(refColumnName);
|
1224
|
+
} else {
|
1225
|
+
fkByTableName[`${tableName}_${id}`] = {
|
1226
|
+
name: "",
|
1227
|
+
tableFrom: tableName,
|
1228
|
+
tableTo: refTableName,
|
1229
|
+
columnsFrom: [columnName],
|
1230
|
+
columnsTo: [refColumnName],
|
1231
|
+
onDelete: deleteRule == null ? void 0 : deleteRule.toLowerCase(),
|
1232
|
+
onUpdate: updateRule == null ? void 0 : updateRule.toLowerCase()
|
1233
|
+
};
|
1234
|
+
}
|
1235
|
+
const columnsFrom = fkByTableName[`${tableName}_${id}`].columnsFrom;
|
1236
|
+
const columnsTo = fkByTableName[`${tableName}_${id}`].columnsTo;
|
1237
|
+
fkByTableName[`${tableName}_${id}`].name = `${tableName}_${columnsFrom.join(
|
1238
|
+
"_"
|
1239
|
+
)}_${refTableName}_${columnsTo.join("_")}_fk`;
|
1240
|
+
}
|
1241
|
+
for (const idx of Object.keys(fkByTableName)) {
|
1242
|
+
const value = fkByTableName[idx];
|
1243
|
+
result[value.tableFrom].foreignKeys[value.name] = value;
|
1244
|
+
}
|
1245
|
+
} catch (e) {
|
1246
|
+
}
|
1247
|
+
if (progressCallback) {
|
1248
|
+
progressCallback("fks", foreignKeysCount, "done");
|
1249
|
+
}
|
1250
|
+
const idxs = await db.query(
|
1251
|
+
`SELECT
|
1252
|
+
m.tbl_name as tableName,
|
1253
|
+
il.name as indexName,
|
1254
|
+
ii.name as columnName,
|
1255
|
+
il.[unique] as isUnique,
|
1256
|
+
il.seq as seq
|
1257
|
+
FROM sqlite_master AS m,
|
1258
|
+
pragma_index_list(m.name) AS il,
|
1259
|
+
pragma_index_info(il.name) AS ii
|
1260
|
+
WHERE
|
1261
|
+
m.type = 'table' and il.name NOT LIKE 'sqlite_autoindex_%';`
|
1262
|
+
);
|
1263
|
+
for (const idxRow of idxs) {
|
1264
|
+
const tableName = idxRow.tableName;
|
1265
|
+
const constraintName = idxRow.indexName;
|
1266
|
+
const columnName = idxRow.columnName;
|
1267
|
+
const isUnique = idxRow.isUnique === 1;
|
1268
|
+
const tableInResult = result[tableName];
|
1269
|
+
if (typeof tableInResult === "undefined")
|
1270
|
+
continue;
|
1271
|
+
indexesCount += 1;
|
1272
|
+
if (progressCallback) {
|
1273
|
+
progressCallback("indexes", indexesCount, "fetching");
|
1274
|
+
}
|
1275
|
+
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
1276
|
+
tableInResult.indexes[constraintName].columns.push(columnName);
|
1277
|
+
} else {
|
1278
|
+
tableInResult.indexes[constraintName] = {
|
1279
|
+
name: constraintName,
|
1280
|
+
columns: [columnName],
|
1281
|
+
isUnique
|
1282
|
+
};
|
1283
|
+
}
|
1284
|
+
}
|
1285
|
+
if (progressCallback) {
|
1286
|
+
progressCallback("indexes", indexesCount, "done");
|
1287
|
+
progressCallback("enums", 0, "done");
|
1288
|
+
}
|
1289
|
+
return {
|
1290
|
+
version: "5",
|
1291
|
+
dialect: "sqlite",
|
1292
|
+
tables: result,
|
1293
|
+
enums: {},
|
1294
|
+
_meta: {
|
1295
|
+
tables: {},
|
1296
|
+
columns: {}
|
1297
|
+
}
|
1298
|
+
};
|
1299
|
+
};
|
1300
|
+
toDrizzle2 = (schema) => {
|
1301
|
+
const tables = {};
|
1302
|
+
Object.values(schema.tables).forEach((t) => {
|
1303
|
+
const columns = {};
|
1304
|
+
Object.values(t.columns).forEach((c) => {
|
1305
|
+
const columnName = c.name;
|
1306
|
+
const type = c.type;
|
1307
|
+
let columnBuilder;
|
1308
|
+
if (type === "integer") {
|
1309
|
+
columnBuilder = new import_sqlite_core.SQLiteIntegerBuilder(columnName);
|
1310
|
+
} else if (type === "text") {
|
1311
|
+
columnBuilder = new import_sqlite_core.SQLiteTextBuilder(columnName, {});
|
1312
|
+
} else if (type === "blob") {
|
1313
|
+
columnBuilder = new import_sqlite_core.SQLiteBlobBufferBuilder(columnName);
|
1314
|
+
} else if (type === "real") {
|
1315
|
+
columnBuilder = new import_sqlite_core.SQLiteRealBuilder(columnName);
|
1316
|
+
} else {
|
1317
|
+
columnBuilder = new import_sqlite_core.SQLiteNumericBuilder(columnName);
|
1318
|
+
}
|
1319
|
+
if (c.notNull) {
|
1320
|
+
columnBuilder = columnBuilder.notNull();
|
1321
|
+
}
|
1322
|
+
if (c.default) {
|
1323
|
+
columnBuilder = columnBuilder.default(c.default);
|
1324
|
+
}
|
1325
|
+
if (c.primaryKey) {
|
1326
|
+
columnBuilder = columnBuilder.primaryKey();
|
1327
|
+
}
|
1328
|
+
columns[columnName] = columnBuilder;
|
1329
|
+
});
|
1330
|
+
tables[t.name] = (0, import_sqlite_core.sqliteTable)(t.name, columns, (cb) => {
|
1331
|
+
const res = {};
|
1332
|
+
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
1333
|
+
const gh = cpk.columns.map((c) => cb[c]);
|
1334
|
+
res[cpk.name] = new import_sqlite_core.PrimaryKeyBuilder(
|
1335
|
+
gh,
|
1336
|
+
cpk.name
|
1337
|
+
);
|
1338
|
+
});
|
1339
|
+
return res;
|
1340
|
+
});
|
1341
|
+
});
|
1342
|
+
return tables;
|
1343
|
+
};
|
1344
|
+
}
|
1345
|
+
});
|
1346
|
+
|
1062
1347
|
// node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js
|
1063
1348
|
var require_readline = __commonJS({
|
1064
1349
|
"node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js"(exports) {
|
@@ -1571,7 +1856,7 @@ var require_hanji = __commonJS({
|
|
1571
1856
|
return;
|
1572
1857
|
}
|
1573
1858
|
exports.render = render2;
|
1574
|
-
function
|
1859
|
+
function renderWithTask3(view, task) {
|
1575
1860
|
return __awaiter(this, void 0, void 0, function* () {
|
1576
1861
|
const terminal = new TaskTerminal(view, process.stdout);
|
1577
1862
|
terminal.requestLayout();
|
@@ -1580,7 +1865,7 @@ var require_hanji = __commonJS({
|
|
1580
1865
|
return result;
|
1581
1866
|
});
|
1582
1867
|
}
|
1583
|
-
exports.renderWithTask =
|
1868
|
+
exports.renderWithTask = renderWithTask3;
|
1584
1869
|
var terminateHandler;
|
1585
1870
|
function onTerminate(callback) {
|
1586
1871
|
terminateHandler = callback;
|
@@ -1813,15 +2098,22 @@ var require_brace_expansion = __commonJS({
|
|
1813
2098
|
var utils_studio_exports = {};
|
1814
2099
|
__export(utils_studio_exports, {
|
1815
2100
|
drizzleSchemaPg: () => toDrizzle,
|
1816
|
-
|
2101
|
+
drizzleSchemaSQLite: () => toDrizzle2,
|
2102
|
+
pgPushIntrospect: () => pgPushIntrospect,
|
2103
|
+
sqlitePushIntrospect: () => sqlitePushIntrospect
|
1817
2104
|
});
|
1818
2105
|
module.exports = __toCommonJS(utils_studio_exports);
|
1819
2106
|
init_pgSerializer();
|
2107
|
+
init_sqliteSerializer();
|
1820
2108
|
|
1821
|
-
// src/cli/commands/
|
1822
|
-
var import_hanji2 = __toESM(require_hanji());
|
2109
|
+
// src/cli/commands/sqliteIntrospect.ts
|
1823
2110
|
init_views();
|
1824
|
-
|
2111
|
+
|
2112
|
+
// src/global.ts
|
2113
|
+
var originUUID = "00000000-0000-0000-0000-000000000000";
|
2114
|
+
|
2115
|
+
// src/cli/commands/sqliteIntrospect.ts
|
2116
|
+
init_sqliteSerializer();
|
1825
2117
|
|
1826
2118
|
// node_modules/.pnpm/camelcase@7.0.1/node_modules/camelcase/index.js
|
1827
2119
|
var UPPERCASE = /[\p{Lu}]/u;
|
@@ -1928,12 +2220,6 @@ Array.prototype.random = function() {
|
|
1928
2220
|
return this[~~(Math.random() * this.length)];
|
1929
2221
|
};
|
1930
2222
|
|
1931
|
-
// src/introspect.ts
|
1932
|
-
init_pgSerializer();
|
1933
|
-
|
1934
|
-
// src/global.ts
|
1935
|
-
var originUUID = "00000000-0000-0000-0000-000000000000";
|
1936
|
-
|
1937
2223
|
// node_modules/.pnpm/minimatch@7.4.3/node_modules/minimatch/dist/mjs/index.js
|
1938
2224
|
var import_brace_expansion = __toESM(require_brace_expansion(), 1);
|
1939
2225
|
|
@@ -2980,6 +3266,35 @@ minimatch.Minimatch = Minimatch;
|
|
2980
3266
|
minimatch.escape = escape;
|
2981
3267
|
minimatch.unescape = unescape;
|
2982
3268
|
|
3269
|
+
// src/cli/commands/sqliteIntrospect.ts
|
3270
|
+
var import_hanji2 = __toESM(require_hanji());
|
3271
|
+
var sqlitePushIntrospect = async (client, filters) => {
|
3272
|
+
const matchers = filters.map((it) => {
|
3273
|
+
return new Minimatch(it);
|
3274
|
+
});
|
3275
|
+
const filter2 = (tableName) => {
|
3276
|
+
if (matchers.length === 0)
|
3277
|
+
return true;
|
3278
|
+
for (let i = 0; i < matchers.length; i++) {
|
3279
|
+
const matcher = matchers[i];
|
3280
|
+
if (matcher.match(tableName))
|
3281
|
+
return true;
|
3282
|
+
}
|
3283
|
+
return false;
|
3284
|
+
};
|
3285
|
+
const res = await fromDatabase2(client, filter2);
|
3286
|
+
const schema = { id: originUUID, prevId: "", ...res };
|
3287
|
+
return { schema };
|
3288
|
+
};
|
3289
|
+
|
3290
|
+
// src/cli/commands/pgIntrospect.ts
|
3291
|
+
var import_hanji3 = __toESM(require_hanji());
|
3292
|
+
init_views();
|
3293
|
+
init_pgSerializer();
|
3294
|
+
|
3295
|
+
// src/introspect.ts
|
3296
|
+
init_pgSerializer();
|
3297
|
+
|
2983
3298
|
// src/cli/commands/pgIntrospect.ts
|
2984
3299
|
var pgPushIntrospect = async (connection, filters, schemaFilters) => {
|
2985
3300
|
const { client } = connection;
|
@@ -3004,5 +3319,7 @@ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
|
|
3004
3319
|
// Annotate the CommonJS export names for ESM import in node:
|
3005
3320
|
0 && (module.exports = {
|
3006
3321
|
drizzleSchemaPg,
|
3007
|
-
|
3322
|
+
drizzleSchemaSQLite,
|
3323
|
+
pgPushIntrospect,
|
3324
|
+
sqlitePushIntrospect
|
3008
3325
|
});
|
package/utils.js
CHANGED
@@ -11729,13 +11729,12 @@ __export(pgSerializer_exports, {
|
|
11729
11729
|
indexName: () => indexName2,
|
11730
11730
|
toDrizzle: () => toDrizzle
|
11731
11731
|
});
|
11732
|
-
var import_pg_core2, import_pg_core3, import_drizzle_orm5,
|
11732
|
+
var import_pg_core2, import_pg_core3, import_drizzle_orm5, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn, toDrizzle;
|
11733
11733
|
var init_pgSerializer = __esm({
|
11734
11734
|
"src/serializer/pgSerializer.ts"() {
|
11735
11735
|
import_pg_core2 = require("drizzle-orm/pg-core");
|
11736
11736
|
import_pg_core3 = require("drizzle-orm/pg-core");
|
11737
11737
|
import_drizzle_orm5 = require("drizzle-orm");
|
11738
|
-
import_drizzle_orm6 = require("drizzle-orm");
|
11739
11738
|
init_serializer();
|
11740
11739
|
init_source();
|
11741
11740
|
init_outputs();
|
@@ -11866,7 +11865,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
11866
11865
|
const onDelete = fk4.onDelete;
|
11867
11866
|
const onUpdate = fk4.onUpdate;
|
11868
11867
|
const reference = fk4.reference();
|
11869
|
-
const tableTo = (0,
|
11868
|
+
const tableTo = (0, import_drizzle_orm5.getTableName)(reference.foreignTable);
|
11870
11869
|
const columnsFrom = reference.columns.map((it) => it.name);
|
11871
11870
|
const columnsTo = reference.foreignColumns.map((it) => it.name);
|
11872
11871
|
return {
|
@@ -12436,11 +12435,11 @@ var sqliteImports_exports = {};
|
|
12436
12435
|
__export(sqliteImports_exports, {
|
12437
12436
|
prepareFromSqliteImports: () => prepareFromSqliteImports
|
12438
12437
|
});
|
12439
|
-
var import_sqlite_core,
|
12438
|
+
var import_sqlite_core, import_drizzle_orm6, prepareFromSqliteImports;
|
12440
12439
|
var init_sqliteImports = __esm({
|
12441
12440
|
"src/serializer/sqliteImports.ts"() {
|
12442
12441
|
import_sqlite_core = require("drizzle-orm/sqlite-core");
|
12443
|
-
|
12442
|
+
import_drizzle_orm6 = require("drizzle-orm");
|
12444
12443
|
init_utils();
|
12445
12444
|
prepareFromSqliteImports = async (imports) => {
|
12446
12445
|
const tables = [];
|
@@ -12451,7 +12450,7 @@ var init_sqliteImports = __esm({
|
|
12451
12450
|
const i0 = require(`${it}`);
|
12452
12451
|
const i0values = Object.values(i0);
|
12453
12452
|
i0values.forEach((t) => {
|
12454
|
-
if ((0,
|
12453
|
+
if ((0, import_drizzle_orm6.is)(t, import_sqlite_core.SQLiteTable)) {
|
12455
12454
|
tables.push(t);
|
12456
12455
|
}
|
12457
12456
|
});
|
@@ -12504,11 +12503,10 @@ function mapSqlToSqliteType(sqlType) {
|
|
12504
12503
|
return "numeric";
|
12505
12504
|
}
|
12506
12505
|
}
|
12507
|
-
var
|
12506
|
+
var import_drizzle_orm7, import_sqlite_core2, dialect5, generateSqliteSnapshot, fromDatabase3, toDrizzle2;
|
12508
12507
|
var init_sqliteSerializer = __esm({
|
12509
12508
|
"src/serializer/sqliteSerializer.ts"() {
|
12510
|
-
|
12511
|
-
import_drizzle_orm9 = require("drizzle-orm");
|
12509
|
+
import_drizzle_orm7 = require("drizzle-orm");
|
12512
12510
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
12513
12511
|
init_serializer();
|
12514
12512
|
init_outputs();
|
@@ -12538,10 +12536,10 @@ var init_sqliteSerializer = __esm({
|
|
12538
12536
|
type: column4.getSQLType(),
|
12539
12537
|
primaryKey,
|
12540
12538
|
notNull,
|
12541
|
-
autoincrement: (0,
|
12539
|
+
autoincrement: (0, import_drizzle_orm7.is)(column4, import_sqlite_core2.SQLiteBaseInteger) ? column4.autoIncrement : false
|
12542
12540
|
};
|
12543
12541
|
if (column4.default !== void 0) {
|
12544
|
-
if ((0,
|
12542
|
+
if ((0, import_drizzle_orm7.is)(column4.default, import_drizzle_orm7.SQL)) {
|
12545
12543
|
columnToSet.default = sqlToStr(column4.default);
|
12546
12544
|
} else {
|
12547
12545
|
columnToSet.default = typeof column4.default === "string" ? `'${column4.default}'` : column4.default;
|
@@ -12581,7 +12579,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12581
12579
|
const onUpdate = fk4.onUpdate ?? "no action";
|
12582
12580
|
const reference = fk4.reference();
|
12583
12581
|
const referenceFT = reference.foreignTable;
|
12584
|
-
const tableTo = (0,
|
12582
|
+
const tableTo = (0, import_drizzle_orm7.getTableName)(referenceFT);
|
12585
12583
|
const columnsFrom = reference.columns.map((it) => it.name);
|
12586
12584
|
const columnsTo = reference.foreignColumns.map((it) => it.name);
|
12587
12585
|
return {
|
@@ -12601,7 +12599,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12601
12599
|
const columns2 = value.config.columns;
|
12602
12600
|
const name = value.config.name;
|
12603
12601
|
let indexColumns = columns2.map((it) => {
|
12604
|
-
if ((0,
|
12602
|
+
if ((0, import_drizzle_orm7.is)(it, import_drizzle_orm7.SQL)) {
|
12605
12603
|
return dialect5.sqlToQuery(it).sql;
|
12606
12604
|
} else {
|
12607
12605
|
return it.name;
|
@@ -12609,7 +12607,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
12609
12607
|
});
|
12610
12608
|
let where = void 0;
|
12611
12609
|
if (value.config.where !== void 0) {
|
12612
|
-
if ((0,
|
12610
|
+
if ((0, import_drizzle_orm7.is)(value.config.where, import_drizzle_orm7.SQL)) {
|
12613
12611
|
where = dialect5.sqlToQuery(value.config.where).sql;
|
12614
12612
|
}
|
12615
12613
|
}
|
@@ -12907,7 +12905,10 @@ WHERE
|
|
12907
12905
|
const res = {};
|
12908
12906
|
Object.values(t.compositePrimaryKeys).forEach((cpk) => {
|
12909
12907
|
const gh = cpk.columns.map((c) => cb[c]);
|
12910
|
-
res[cpk.name] = new import_sqlite_core2.PrimaryKeyBuilder(
|
12908
|
+
res[cpk.name] = new import_sqlite_core2.PrimaryKeyBuilder(
|
12909
|
+
gh,
|
12910
|
+
cpk.name
|
12911
|
+
);
|
12911
12912
|
});
|
12912
12913
|
return res;
|
12913
12914
|
});
|
@@ -12927,13 +12928,13 @@ var init_serializer = __esm({
|
|
12927
12928
|
init_source();
|
12928
12929
|
sqlToStr = (sql2) => {
|
12929
12930
|
return sql2.toQuery({
|
12930
|
-
escapeName: (
|
12931
|
+
escapeName: () => {
|
12931
12932
|
throw new Error("we don't support params for `sql` default values");
|
12932
12933
|
},
|
12933
|
-
escapeParam: (
|
12934
|
+
escapeParam: () => {
|
12934
12935
|
throw new Error("we don't support params for `sql` default values");
|
12935
12936
|
},
|
12936
|
-
escapeString: (
|
12937
|
+
escapeString: () => {
|
12937
12938
|
throw new Error("we don't support params for `sql` default values");
|
12938
12939
|
}
|
12939
12940
|
}).sql;
|
@@ -19269,10 +19270,10 @@ __export(drivers_exports, {
|
|
19269
19270
|
PgPostgres: () => PgPostgres,
|
19270
19271
|
TursoSqlite: () => TursoSqlite
|
19271
19272
|
});
|
19272
|
-
var
|
19273
|
+
var import_drizzle_orm8, DrizzleDbClient, DrizzleORMPgClient, BetterSqlite, TursoSqlite, PgPostgres;
|
19273
19274
|
var init_drivers = __esm({
|
19274
19275
|
"src/drivers/index.ts"() {
|
19275
|
-
|
19276
|
+
import_drizzle_orm8 = require("drizzle-orm");
|
19276
19277
|
DrizzleDbClient = class {
|
19277
19278
|
constructor(db) {
|
19278
19279
|
this.db = db;
|
@@ -19280,11 +19281,11 @@ var init_drivers = __esm({
|
|
19280
19281
|
};
|
19281
19282
|
DrizzleORMPgClient = class extends DrizzleDbClient {
|
19282
19283
|
async query(query, values) {
|
19283
|
-
const res = await this.db.execute(
|
19284
|
+
const res = await this.db.execute(import_drizzle_orm8.sql.raw(query));
|
19284
19285
|
return res.rows;
|
19285
19286
|
}
|
19286
19287
|
async run(query) {
|
19287
|
-
const res = await this.db.execute(
|
19288
|
+
const res = await this.db.execute(import_drizzle_orm8.sql.raw(query));
|
19288
19289
|
return res.rows;
|
19289
19290
|
}
|
19290
19291
|
};
|
@@ -19327,18 +19328,18 @@ var init_sqliteIntrospect = __esm({
|
|
19327
19328
|
init_sqlite_introspect();
|
19328
19329
|
init_mjs();
|
19329
19330
|
import_hanji7 = __toESM(require_hanji());
|
19330
|
-
init_drivers();
|
19331
19331
|
connectToSQLite = async (config) => {
|
19332
|
+
const { BetterSqlite: BetterSqlite2, TursoSqlite: TursoSqlite2 } = await Promise.resolve().then(() => (init_drivers(), drivers_exports));
|
19332
19333
|
if (config.driver === "better-sqlite") {
|
19333
19334
|
const { default: Database } = await import("better-sqlite3");
|
19334
19335
|
return {
|
19335
|
-
client: new
|
19336
|
+
client: new BetterSqlite2(new Database(config.dbCredentials.url))
|
19336
19337
|
};
|
19337
19338
|
}
|
19338
19339
|
if (config.driver === "libsql") {
|
19339
19340
|
const { createClient } = await import("@libsql/client");
|
19340
19341
|
return {
|
19341
|
-
client: new
|
19342
|
+
client: new TursoSqlite2(
|
19342
19343
|
createClient({
|
19343
19344
|
url: config.dbCredentials.url
|
19344
19345
|
})
|
@@ -19347,7 +19348,7 @@ var init_sqliteIntrospect = __esm({
|
|
19347
19348
|
} else {
|
19348
19349
|
const { createClient } = await import("@libsql/client");
|
19349
19350
|
return {
|
19350
|
-
client: new
|
19351
|
+
client: new TursoSqlite2(
|
19351
19352
|
createClient({
|
19352
19353
|
url: config.dbCredentials.url,
|
19353
19354
|
authToken: config.dbCredentials.authToken
|
@@ -40475,14 +40476,14 @@ var require_promise = __commonJS({
|
|
40475
40476
|
});
|
40476
40477
|
|
40477
40478
|
// src/orm-extenstions/d1-driver/session.ts
|
40478
|
-
var
|
40479
|
+
var import_drizzle_orm9, import_drizzle_orm10, import_drizzle_orm11, import_sqlite_core3, import_drizzle_orm12, _a, SQLiteWranglerD1Session, _a2, PreparedQuery;
|
40479
40480
|
var init_session = __esm({
|
40480
40481
|
"src/orm-extenstions/d1-driver/session.ts"() {
|
40482
|
+
import_drizzle_orm9 = require("drizzle-orm");
|
40483
|
+
import_drizzle_orm10 = require("drizzle-orm");
|
40481
40484
|
import_drizzle_orm11 = require("drizzle-orm");
|
40482
|
-
import_drizzle_orm12 = require("drizzle-orm");
|
40483
|
-
import_drizzle_orm13 = require("drizzle-orm");
|
40484
40485
|
import_sqlite_core3 = require("drizzle-orm/sqlite-core");
|
40485
|
-
|
40486
|
+
import_drizzle_orm12 = require("drizzle-orm");
|
40486
40487
|
SQLiteWranglerD1Session = class extends import_sqlite_core3.SQLiteSession {
|
40487
40488
|
constructor(client, configPath, dbName, dialect6, schema4, options = {}) {
|
40488
40489
|
super(dialect6);
|
@@ -40491,7 +40492,7 @@ var init_session = __esm({
|
|
40491
40492
|
this.dbName = dbName;
|
40492
40493
|
this.schema = schema4;
|
40493
40494
|
this.options = options;
|
40494
|
-
this.logger = options.logger ?? new
|
40495
|
+
this.logger = options.logger ?? new import_drizzle_orm10.NoopLogger();
|
40495
40496
|
}
|
40496
40497
|
prepareQuery(query, fields, executeMethod, customResultMapper) {
|
40497
40498
|
return new PreparedQuery(
|
@@ -40510,7 +40511,7 @@ var init_session = __esm({
|
|
40510
40511
|
throw new Error("no transaction support yet");
|
40511
40512
|
}
|
40512
40513
|
};
|
40513
|
-
_a =
|
40514
|
+
_a = import_drizzle_orm9.entityKind;
|
40514
40515
|
SQLiteWranglerD1Session[_a] = "SQLiteD1Session";
|
40515
40516
|
PreparedQuery = class extends import_sqlite_core3.PreparedQuery {
|
40516
40517
|
constructor(stmt, configPath, dbName, queryString, params, logger, fields, executeMethod, customResultMapper) {
|
@@ -40525,14 +40526,14 @@ var init_session = __esm({
|
|
40525
40526
|
this.customResultMapper = customResultMapper;
|
40526
40527
|
}
|
40527
40528
|
run(placeholderValues) {
|
40528
|
-
const params = (0,
|
40529
|
+
const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
|
40529
40530
|
this.logger.logQuery(this.queryString, params);
|
40530
40531
|
return this.stmt(this.queryString, this.configPath, this.dbName);
|
40531
40532
|
}
|
40532
40533
|
async all(placeholderValues) {
|
40533
40534
|
const { fields, queryString, logger, stmt, customResultMapper } = this;
|
40534
40535
|
if (!fields && !customResultMapper) {
|
40535
|
-
const params = (0,
|
40536
|
+
const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
|
40536
40537
|
logger.logQuery(queryString, params);
|
40537
40538
|
return stmt(this.queryString, this.configPath, this.dbName).then(
|
40538
40539
|
({ results }) => results
|
@@ -40542,12 +40543,12 @@ var init_session = __esm({
|
|
40542
40543
|
if (customResultMapper) {
|
40543
40544
|
return customResultMapper(rows);
|
40544
40545
|
}
|
40545
|
-
return rows.map((row) => (0,
|
40546
|
+
return rows.map((row) => (0, import_drizzle_orm12.mapResultRow)(fields, row, void 0));
|
40546
40547
|
}
|
40547
40548
|
async get(placeholderValues) {
|
40548
40549
|
const { fields, queryString, logger, stmt, customResultMapper } = this;
|
40549
40550
|
if (!fields && !customResultMapper) {
|
40550
|
-
const params = (0,
|
40551
|
+
const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
|
40551
40552
|
logger.logQuery(queryString, params);
|
40552
40553
|
return stmt(queryString, this.configPath, this.dbName).then(
|
40553
40554
|
({ results }) => results[0]
|
@@ -40571,13 +40572,13 @@ var init_session = __esm({
|
|
40571
40572
|
return rows;
|
40572
40573
|
}
|
40573
40574
|
async values(placeholderValues) {
|
40574
|
-
const params = (0,
|
40575
|
+
const params = (0, import_drizzle_orm11.fillPlaceholders)(this.params, placeholderValues ?? {});
|
40575
40576
|
this.logger.logQuery(this.queryString, params);
|
40576
40577
|
const wranglerRes = await this.stmt(this.queryString, this.configPath, this.dbName);
|
40577
40578
|
return this.d1ToRawMapping(wranglerRes.results);
|
40578
40579
|
}
|
40579
40580
|
};
|
40580
|
-
_a2 =
|
40581
|
+
_a2 = import_drizzle_orm9.entityKind;
|
40581
40582
|
PreparedQuery[_a2] = "D1PreparedQuery";
|
40582
40583
|
}
|
40583
40584
|
});
|
@@ -40611,15 +40612,15 @@ function drizzle(client, configPath, dbName, config = {}) {
|
|
40611
40612
|
const dialect6 = new WranglerDialect();
|
40612
40613
|
let logger;
|
40613
40614
|
if (config.logger === true) {
|
40614
|
-
logger = new
|
40615
|
+
logger = new import_drizzle_orm13.DefaultLogger();
|
40615
40616
|
} else if (config.logger !== false) {
|
40616
40617
|
logger = config.logger;
|
40617
40618
|
}
|
40618
40619
|
let schema4;
|
40619
40620
|
if (config.schema) {
|
40620
|
-
const tablesConfig = (0,
|
40621
|
+
const tablesConfig = (0, import_drizzle_orm13.extractTablesRelationalConfig)(
|
40621
40622
|
config.schema,
|
40622
|
-
|
40623
|
+
import_drizzle_orm13.createTableRelationsHelpers
|
40623
40624
|
);
|
40624
40625
|
schema4 = {
|
40625
40626
|
fullSchema: config.schema,
|
@@ -40637,10 +40638,10 @@ function drizzle(client, configPath, dbName, config = {}) {
|
|
40637
40638
|
schema4
|
40638
40639
|
);
|
40639
40640
|
}
|
40640
|
-
var
|
40641
|
+
var import_drizzle_orm13, import_sqlite_core4, WranglerDialect;
|
40641
40642
|
var init_driver = __esm({
|
40642
40643
|
"src/orm-extenstions/d1-driver/driver.ts"() {
|
40643
|
-
|
40644
|
+
import_drizzle_orm13 = require("drizzle-orm");
|
40644
40645
|
import_sqlite_core4 = require("drizzle-orm/sqlite-core");
|
40645
40646
|
init_session();
|
40646
40647
|
WranglerDialect = class extends import_sqlite_core4.SQLiteAsyncDialect {
|
@@ -55950,10 +55951,10 @@ var init_wrangler_client = __esm({
|
|
55950
55951
|
});
|
55951
55952
|
|
55952
55953
|
// src/serializer/studioUtils.ts
|
55953
|
-
var
|
55954
|
+
var import_drizzle_orm14, import_mysql_core4, import_pg_core4, import_sqlite_core5, drizzleDb;
|
55954
55955
|
var init_studioUtils = __esm({
|
55955
55956
|
"src/serializer/studioUtils.ts"() {
|
55956
|
-
|
55957
|
+
import_drizzle_orm14 = require("drizzle-orm");
|
55957
55958
|
import_mysql_core4 = require("drizzle-orm/mysql-core");
|
55958
55959
|
import_pg_core4 = require("drizzle-orm/pg-core");
|
55959
55960
|
import_sqlite_core5 = require("drizzle-orm/sqlite-core");
|