drizzle-seed 0.3.1 → 0.3.2-97009ae
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/index.cjs +62 -57
- package/index.cjs.map +1 -1
- package/index.d.cts +9 -4
- package/index.d.mts +9 -4
- package/index.d.ts +9 -4
- package/index.mjs +62 -57
- package/index.mjs.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -5,11 +5,12 @@ import type { PgColumn, PgSchema } from 'drizzle-orm/pg-core';
|
|
|
5
5
|
import { PgDatabase, PgTable } from 'drizzle-orm/pg-core';
|
|
6
6
|
import type { SQLiteColumn } from 'drizzle-orm/sqlite-core';
|
|
7
7
|
import { BaseSQLiteDatabase, SQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
8
|
+
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
8
9
|
import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js';
|
|
9
10
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
10
11
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
11
12
|
import type { RefinementsType } from './types/seedService.js';
|
|
12
|
-
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
13
|
+
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
13
14
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
14
15
|
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
15
16
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
@@ -57,7 +58,7 @@ type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any>
|
|
|
57
58
|
};
|
|
58
59
|
};
|
|
59
60
|
} : {} : {};
|
|
60
|
-
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
61
|
+
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
61
62
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
62
63
|
}, VERSION extends string | undefined> implements Promise<void> {
|
|
63
64
|
private db;
|
|
@@ -278,7 +279,7 @@ export declare function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject,
|
|
|
278
279
|
*
|
|
279
280
|
* ```
|
|
280
281
|
*/
|
|
281
|
-
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
282
|
+
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
282
283
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations | any;
|
|
283
284
|
}, VERSION extends '2' | '1' | undefined>(db: DB, schema: SCHEMA, options?: {
|
|
284
285
|
count?: number;
|
|
@@ -323,9 +324,13 @@ export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any
|
|
|
323
324
|
* @example
|
|
324
325
|
* ```ts
|
|
325
326
|
* await reset(db, schema);
|
|
327
|
+
*
|
|
328
|
+
* // Alternatively, you can provide an object containing your tables
|
|
329
|
+
* // as the `schema` parameter when calling `reset`.
|
|
330
|
+
* await reset(db, { users });
|
|
326
331
|
* ```
|
|
327
332
|
*/
|
|
328
|
-
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
333
|
+
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
329
334
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | any;
|
|
330
335
|
}>(db: DB, schema: SCHEMA): Promise<void>;
|
|
331
336
|
export { default as cities } from './datasets/cityNames.js';
|
package/index.d.mts
CHANGED
|
@@ -5,11 +5,12 @@ import type { PgColumn, PgSchema } from 'drizzle-orm/pg-core';
|
|
|
5
5
|
import { PgDatabase, PgTable } from 'drizzle-orm/pg-core';
|
|
6
6
|
import type { SQLiteColumn } from 'drizzle-orm/sqlite-core';
|
|
7
7
|
import { BaseSQLiteDatabase, SQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
8
|
+
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
8
9
|
import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js';
|
|
9
10
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
10
11
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
11
12
|
import type { RefinementsType } from './types/seedService.js';
|
|
12
|
-
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
13
|
+
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
13
14
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
14
15
|
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
15
16
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
@@ -57,7 +58,7 @@ type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any>
|
|
|
57
58
|
};
|
|
58
59
|
};
|
|
59
60
|
} : {} : {};
|
|
60
|
-
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
61
|
+
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
61
62
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
62
63
|
}, VERSION extends string | undefined> implements Promise<void> {
|
|
63
64
|
private db;
|
|
@@ -278,7 +279,7 @@ export declare function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject,
|
|
|
278
279
|
*
|
|
279
280
|
* ```
|
|
280
281
|
*/
|
|
281
|
-
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
282
|
+
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
282
283
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations | any;
|
|
283
284
|
}, VERSION extends '2' | '1' | undefined>(db: DB, schema: SCHEMA, options?: {
|
|
284
285
|
count?: number;
|
|
@@ -323,9 +324,13 @@ export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any
|
|
|
323
324
|
* @example
|
|
324
325
|
* ```ts
|
|
325
326
|
* await reset(db, schema);
|
|
327
|
+
*
|
|
328
|
+
* // Alternatively, you can provide an object containing your tables
|
|
329
|
+
* // as the `schema` parameter when calling `reset`.
|
|
330
|
+
* await reset(db, { users });
|
|
326
331
|
* ```
|
|
327
332
|
*/
|
|
328
|
-
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
333
|
+
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
329
334
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | any;
|
|
330
335
|
}>(db: DB, schema: SCHEMA): Promise<void>;
|
|
331
336
|
export { default as cities } from './datasets/cityNames.js';
|
package/index.d.ts
CHANGED
|
@@ -5,11 +5,12 @@ import type { PgColumn, PgSchema } from 'drizzle-orm/pg-core';
|
|
|
5
5
|
import { PgDatabase, PgTable } from 'drizzle-orm/pg-core';
|
|
6
6
|
import type { SQLiteColumn } from 'drizzle-orm/sqlite-core';
|
|
7
7
|
import { BaseSQLiteDatabase, SQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
8
|
+
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
8
9
|
import { generatorsFuncs, generatorsFuncsV2 } from './services/GeneratorFuncs.js';
|
|
9
10
|
import type { AbstractGenerator } from './services/Generators.js';
|
|
10
11
|
import type { DrizzleStudioObjectType, DrizzleStudioRelationType } from './types/drizzleStudio.js';
|
|
11
12
|
import type { RefinementsType } from './types/seedService.js';
|
|
12
|
-
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
13
|
+
type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
13
14
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
14
15
|
}> = DB extends PgDatabase<any, any> ? SCHEMA extends {
|
|
15
16
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
@@ -57,7 +58,7 @@ type InferCallbackType<DB extends PgDatabase<any, any> | MySqlDatabase<any, any>
|
|
|
57
58
|
};
|
|
58
59
|
};
|
|
59
60
|
} : {} : {};
|
|
60
|
-
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
61
|
+
declare class SeedPromise<DB extends PgDatabase<any, any> | MySqlDatabase<any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
61
62
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations;
|
|
62
63
|
}, VERSION extends string | undefined> implements Promise<void> {
|
|
63
64
|
private db;
|
|
@@ -278,7 +279,7 @@ export declare function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject,
|
|
|
278
279
|
*
|
|
279
280
|
* ```
|
|
280
281
|
*/
|
|
281
|
-
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
282
|
+
export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
282
283
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | Relations | any;
|
|
283
284
|
}, VERSION extends '2' | '1' | undefined>(db: DB, schema: SCHEMA, options?: {
|
|
284
285
|
count?: number;
|
|
@@ -323,9 +324,13 @@ export declare function seed<DB extends PgDatabase<any, any> | MySqlDatabase<any
|
|
|
323
324
|
* @example
|
|
324
325
|
* ```ts
|
|
325
326
|
* await reset(db, schema);
|
|
327
|
+
*
|
|
328
|
+
* // Alternatively, you can provide an object containing your tables
|
|
329
|
+
* // as the `schema` parameter when calling `reset`.
|
|
330
|
+
* await reset(db, { users });
|
|
326
331
|
* ```
|
|
327
332
|
*/
|
|
328
|
-
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any>, SCHEMA extends {
|
|
333
|
+
export declare function reset<DB extends PgDatabase<any, any> | MySqlDatabase<any, any, any, any> | BaseSQLiteDatabase<any, any> | LibSQLDatabase<any>, SCHEMA extends {
|
|
329
334
|
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable | any;
|
|
330
335
|
}>(db: DB, schema: SCHEMA): Promise<void>;
|
|
331
336
|
export { default as cities } from './datasets/cityNames.js';
|
package/index.mjs
CHANGED
|
@@ -134582,17 +134582,15 @@ class SeedService {
|
|
|
134582
134582
|
return generator;
|
|
134583
134583
|
}
|
|
134584
134584
|
// INT ------------------------------------------------------------------------------------------------------------
|
|
134585
|
-
if ((col.columnType
|
|
134586
|
-
||
|
|
134587
|
-
|| col.columnType === 'smallint'
|
|
134588
|
-
|| col.columnType.includes('bigint'))
|
|
134585
|
+
if ((['smallserial', 'serial', 'bigserial'].includes(col.columnType)
|
|
134586
|
+
|| ['smallint', 'integer', 'bigint'].includes(col.columnType))
|
|
134589
134587
|
&& table.primaryKeys.includes(col.name)) {
|
|
134590
134588
|
const generator = new generatorsMap.GenerateIntPrimaryKey[0]();
|
|
134591
134589
|
return generator;
|
|
134592
134590
|
}
|
|
134593
134591
|
let minValue;
|
|
134594
134592
|
let maxValue;
|
|
134595
|
-
if (col.columnType
|
|
134593
|
+
if (['smallserial', 'serial', 'bigserial'].includes(col.columnType)) {
|
|
134596
134594
|
minValue = 1;
|
|
134597
134595
|
if (col.columnType === 'smallserial') {
|
|
134598
134596
|
// 2^16 / 2 - 1, 2 bytes
|
|
@@ -134608,7 +134606,7 @@ class SeedService {
|
|
|
134608
134606
|
maxValue = BigInt('9223372036854775807');
|
|
134609
134607
|
}
|
|
134610
134608
|
}
|
|
134611
|
-
else if (col.columnType
|
|
134609
|
+
else if (['smallint', 'integer', 'bigint'].includes(col.columnType)) {
|
|
134612
134610
|
if (col.columnType === 'smallint') {
|
|
134613
134611
|
// 2^16 / 2 - 1, 2 bytes
|
|
134614
134612
|
minValue = -32768;
|
|
@@ -134633,25 +134631,23 @@ class SeedService {
|
|
|
134633
134631
|
}
|
|
134634
134632
|
}
|
|
134635
134633
|
}
|
|
134636
|
-
if (col.columnType
|
|
134637
|
-
&& !col.columnType.includes('interval')
|
|
134638
|
-
&& !col.columnType.includes('point')) {
|
|
134634
|
+
if (['smallint', 'integer', 'bigint'].includes(col.columnType)) {
|
|
134639
134635
|
const generator = new generatorsMap.GenerateInt[0]({
|
|
134640
134636
|
minValue,
|
|
134641
134637
|
maxValue,
|
|
134642
134638
|
});
|
|
134643
134639
|
return generator;
|
|
134644
134640
|
}
|
|
134645
|
-
if (col.columnType
|
|
134641
|
+
if (['smallserial', 'serial', 'bigserial'].includes(col.columnType)) {
|
|
134646
134642
|
const generator = new generatorsMap.GenerateIntPrimaryKey[0]();
|
|
134647
134643
|
generator.maxValue = maxValue;
|
|
134648
134644
|
return generator;
|
|
134649
134645
|
}
|
|
134650
134646
|
// NUMBER(real, double, decimal, numeric)
|
|
134651
|
-
if (col.columnType
|
|
134652
|
-
|| col.columnType
|
|
134653
|
-
|| col.columnType.
|
|
134654
|
-
|| col.columnType.
|
|
134647
|
+
if (col.columnType === 'real'
|
|
134648
|
+
|| col.columnType === 'double precision'
|
|
134649
|
+
|| col.columnType.match(/^decimal(\(\d+,? *\d*\))?$/) !== null
|
|
134650
|
+
|| col.columnType.match(/^numeric(\(\d+,? *\d*\))?$/) !== null) {
|
|
134655
134651
|
if (col.typeParams.precision !== undefined) {
|
|
134656
134652
|
const precision = col.typeParams.precision;
|
|
134657
134653
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -134668,29 +134664,29 @@ class SeedService {
|
|
|
134668
134664
|
}
|
|
134669
134665
|
// STRING
|
|
134670
134666
|
if ((col.columnType === 'text'
|
|
134671
|
-
|| col.columnType.
|
|
134672
|
-
|| col.columnType.
|
|
134667
|
+
|| col.columnType.match(/^varchar(\(\d+\))?$/) !== null
|
|
134668
|
+
|| col.columnType.match(/^char(\(\d+\))?$/) !== null)
|
|
134673
134669
|
&& table.primaryKeys.includes(col.name)) {
|
|
134674
134670
|
const generator = new generatorsMap.GenerateUniqueString[0]();
|
|
134675
134671
|
return generator;
|
|
134676
134672
|
}
|
|
134677
134673
|
if ((col.columnType === 'text'
|
|
134678
|
-
|| col.columnType.
|
|
134679
|
-
|| col.columnType.
|
|
134674
|
+
|| col.columnType.match(/^varchar(\(\d+\))?$/) !== null
|
|
134675
|
+
|| col.columnType.match(/^char(\(\d+\))?$/) !== null)
|
|
134680
134676
|
&& col.name.toLowerCase().includes('name')) {
|
|
134681
134677
|
const generator = new generatorsMap.GenerateFirstName[0]();
|
|
134682
134678
|
return generator;
|
|
134683
134679
|
}
|
|
134684
134680
|
if ((col.columnType === 'text'
|
|
134685
|
-
|| col.columnType.
|
|
134686
|
-
|| col.columnType.
|
|
134681
|
+
|| col.columnType.match(/^varchar(\(\d+\))?$/) !== null
|
|
134682
|
+
|| col.columnType.match(/^char(\(\d+\))?$/) !== null)
|
|
134687
134683
|
&& col.name.toLowerCase().includes('email')) {
|
|
134688
134684
|
const generator = new generatorsMap.GenerateEmail[0]();
|
|
134689
134685
|
return generator;
|
|
134690
134686
|
}
|
|
134691
134687
|
if (col.columnType === 'text'
|
|
134692
|
-
|| col.columnType.
|
|
134693
|
-
|| col.columnType.
|
|
134688
|
+
|| col.columnType.match(/^varchar(\(\d+\))?$/) !== null
|
|
134689
|
+
|| col.columnType.match(/^char(\(\d+\))?$/) !== null) {
|
|
134694
134690
|
const generator = new generatorsMap.GenerateString[0]();
|
|
134695
134691
|
return generator;
|
|
134696
134692
|
}
|
|
@@ -134705,15 +134701,15 @@ class SeedService {
|
|
|
134705
134701
|
return generator;
|
|
134706
134702
|
}
|
|
134707
134703
|
// DATE, TIME, TIMESTAMP
|
|
134708
|
-
if (col.columnType
|
|
134704
|
+
if (col.columnType === 'date') {
|
|
134709
134705
|
const generator = new generatorsMap.GenerateDate[0]();
|
|
134710
134706
|
return generator;
|
|
134711
134707
|
}
|
|
134712
|
-
if (col.columnType
|
|
134708
|
+
if (col.columnType.match(/^time((\(\d+\))|( with time zone))?$/) !== null) {
|
|
134713
134709
|
const generator = new generatorsMap.GenerateTime[0]();
|
|
134714
134710
|
return generator;
|
|
134715
134711
|
}
|
|
134716
|
-
if (col.columnType.
|
|
134712
|
+
if (col.columnType.match(/^timestamp((\(\d+\))|( with time zone))?$/) !== null) {
|
|
134717
134713
|
const generator = new generatorsMap.GenerateTimestamp[0]();
|
|
134718
134714
|
return generator;
|
|
134719
134715
|
}
|
|
@@ -134734,7 +134730,7 @@ class SeedService {
|
|
|
134734
134730
|
return generator;
|
|
134735
134731
|
}
|
|
134736
134732
|
// INTERVAL
|
|
134737
|
-
if (col.columnType.
|
|
134733
|
+
if (col.columnType.match(/^interval( .+)?$/) !== null) {
|
|
134738
134734
|
if (col.columnType === 'interval') {
|
|
134739
134735
|
const generator = new generatorsMap.GenerateInterval[0]();
|
|
134740
134736
|
return generator;
|
|
@@ -134744,11 +134740,11 @@ class SeedService {
|
|
|
134744
134740
|
return generator;
|
|
134745
134741
|
}
|
|
134746
134742
|
// POINT, LINE
|
|
134747
|
-
if (col.columnType
|
|
134743
|
+
if (col.columnType === 'point') {
|
|
134748
134744
|
const generator = new generatorsMap.GeneratePoint[0]();
|
|
134749
134745
|
return generator;
|
|
134750
134746
|
}
|
|
134751
|
-
if (col.columnType
|
|
134747
|
+
if (col.columnType === 'line') {
|
|
134752
134748
|
const generator = new generatorsMap.GenerateLine[0]();
|
|
134753
134749
|
return generator;
|
|
134754
134750
|
}
|
|
@@ -134771,7 +134767,8 @@ class SeedService {
|
|
|
134771
134767
|
selectGeneratorForMysqlColumn = (table, col) => {
|
|
134772
134768
|
const pickGenerator = (table, col) => {
|
|
134773
134769
|
// INT ------------------------------------------------------------------------------------------------------------
|
|
134774
|
-
if ((col.columnType
|
|
134770
|
+
if ((col.columnType === 'serial'
|
|
134771
|
+
|| ['tinyint', 'smallint', 'mediumint', 'int', 'bigint'].includes(col.columnType))
|
|
134775
134772
|
&& table.primaryKeys.includes(col.name)) {
|
|
134776
134773
|
const generator = new generatorsMap.GenerateIntPrimaryKey[0]();
|
|
134777
134774
|
return generator;
|
|
@@ -134783,7 +134780,7 @@ class SeedService {
|
|
|
134783
134780
|
minValue = BigInt(0);
|
|
134784
134781
|
maxValue = BigInt('9223372036854775807');
|
|
134785
134782
|
}
|
|
134786
|
-
else if (col.columnType
|
|
134783
|
+
else if (['tinyint', 'smallint', 'mediumint', 'int', 'bigint'].includes(col.columnType)) {
|
|
134787
134784
|
if (col.columnType === 'tinyint') {
|
|
134788
134785
|
// 2^8 / 2 - 1, 1 bytes
|
|
134789
134786
|
minValue = -128;
|
|
@@ -134810,24 +134807,24 @@ class SeedService {
|
|
|
134810
134807
|
maxValue = BigInt('9223372036854775807');
|
|
134811
134808
|
}
|
|
134812
134809
|
}
|
|
134813
|
-
if (col.columnType
|
|
134810
|
+
if (['tinyint', 'smallint', 'mediumint', 'int', 'bigint'].includes(col.columnType)) {
|
|
134814
134811
|
const generator = new generatorsMap.GenerateInt[0]({
|
|
134815
134812
|
minValue,
|
|
134816
134813
|
maxValue,
|
|
134817
134814
|
});
|
|
134818
134815
|
return generator;
|
|
134819
134816
|
}
|
|
134820
|
-
if (col.columnType
|
|
134817
|
+
if (col.columnType === 'serial') {
|
|
134821
134818
|
const generator = new generatorsMap.GenerateIntPrimaryKey[0]();
|
|
134822
134819
|
generator.maxValue = maxValue;
|
|
134823
134820
|
return generator;
|
|
134824
134821
|
}
|
|
134825
134822
|
// NUMBER(real, double, decimal, float)
|
|
134826
|
-
if (col.columnType
|
|
134827
|
-
|| col.columnType
|
|
134828
|
-
|| col.columnType
|
|
134829
|
-
|| col.columnType.
|
|
134830
|
-
|| col.columnType.
|
|
134823
|
+
if (col.columnType === 'real'
|
|
134824
|
+
|| col.columnType === 'double'
|
|
134825
|
+
|| col.columnType === 'float'
|
|
134826
|
+
|| col.columnType.match(/^decimal(\(\d+,? *\d*\))?$/) !== null
|
|
134827
|
+
|| col.columnType.match(/^numeric(\(\d+,? *\d*\))?$/) !== null) {
|
|
134831
134828
|
if (col.typeParams.precision !== undefined) {
|
|
134832
134829
|
const precision = col.typeParams.precision;
|
|
134833
134830
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -134845,40 +134842,40 @@ class SeedService {
|
|
|
134845
134842
|
// STRING
|
|
134846
134843
|
if ((col.columnType === 'text'
|
|
134847
134844
|
|| col.columnType === 'blob'
|
|
134848
|
-
|| col.columnType.
|
|
134849
|
-
|| col.columnType.
|
|
134850
|
-
|| col.columnType.
|
|
134851
|
-
|| col.columnType.
|
|
134845
|
+
|| col.columnType.match(/^char(\(\d+\))?$/) !== null
|
|
134846
|
+
|| col.columnType.match(/^varchar(\(\d+\))?$/) !== null
|
|
134847
|
+
|| col.columnType.match(/^binary(\(\d+\))?$/) !== null
|
|
134848
|
+
|| col.columnType.match(/^varbinary(\(\d+\))?$/) !== null)
|
|
134852
134849
|
&& table.primaryKeys.includes(col.name)) {
|
|
134853
134850
|
const generator = new generatorsMap.GenerateUniqueString[0]();
|
|
134854
134851
|
return generator;
|
|
134855
134852
|
}
|
|
134856
134853
|
if ((col.columnType === 'text'
|
|
134857
134854
|
|| col.columnType === 'blob'
|
|
134858
|
-
|| col.columnType.
|
|
134859
|
-
|| col.columnType.
|
|
134860
|
-
|| col.columnType.
|
|
134861
|
-
|| col.columnType.
|
|
134855
|
+
|| col.columnType.match(/^char(\(\d+\))?$/) !== null
|
|
134856
|
+
|| col.columnType.match(/^varchar(\(\d+\))?$/) !== null
|
|
134857
|
+
|| col.columnType.match(/^binary(\(\d+\))?$/) !== null
|
|
134858
|
+
|| col.columnType.match(/^varbinary(\(\d+\))?$/) !== null)
|
|
134862
134859
|
&& col.name.toLowerCase().includes('name')) {
|
|
134863
134860
|
const generator = new generatorsMap.GenerateFirstName[0]();
|
|
134864
134861
|
return generator;
|
|
134865
134862
|
}
|
|
134866
134863
|
if ((col.columnType === 'text'
|
|
134867
134864
|
|| col.columnType === 'blob'
|
|
134868
|
-
|| col.columnType.
|
|
134869
|
-
|| col.columnType.
|
|
134870
|
-
|| col.columnType.
|
|
134871
|
-
|| col.columnType.
|
|
134865
|
+
|| col.columnType.match(/^char(\(\d+\))?$/) !== null
|
|
134866
|
+
|| col.columnType.match(/^varchar(\(\d+\))?$/) !== null
|
|
134867
|
+
|| col.columnType.match(/^binary(\(\d+\))?$/) !== null
|
|
134868
|
+
|| col.columnType.match(/^varbinary(\(\d+\))?$/) !== null)
|
|
134872
134869
|
&& col.name.toLowerCase().includes('email')) {
|
|
134873
134870
|
const generator = new generatorsMap.GenerateEmail[0]();
|
|
134874
134871
|
return generator;
|
|
134875
134872
|
}
|
|
134876
134873
|
if (col.columnType === 'text'
|
|
134877
134874
|
|| col.columnType === 'blob'
|
|
134878
|
-
|| col.columnType.
|
|
134879
|
-
|| col.columnType.
|
|
134880
|
-
|| col.columnType.
|
|
134881
|
-
|| col.columnType.
|
|
134875
|
+
|| col.columnType.match(/^char(\(\d+\))?$/) !== null
|
|
134876
|
+
|| col.columnType.match(/^varchar(\(\d+\))?$/) !== null
|
|
134877
|
+
|| col.columnType.match(/^binary(\(\d+\))?$/) !== null
|
|
134878
|
+
|| col.columnType.match(/^varbinary(\(\d+\))?$/) !== null) {
|
|
134882
134879
|
const generator = new generatorsMap.GenerateString[0]();
|
|
134883
134880
|
return generator;
|
|
134884
134881
|
}
|
|
@@ -134888,11 +134885,11 @@ class SeedService {
|
|
|
134888
134885
|
return generator;
|
|
134889
134886
|
}
|
|
134890
134887
|
// DATE, TIME, TIMESTAMP, DATETIME, YEAR
|
|
134891
|
-
if (col.columnType.
|
|
134888
|
+
if (col.columnType.match(/^datetime(\(\d\))?$/) !== null) {
|
|
134892
134889
|
const generator = new generatorsMap.GenerateDatetime[0]();
|
|
134893
134890
|
return generator;
|
|
134894
134891
|
}
|
|
134895
|
-
if (col.columnType
|
|
134892
|
+
if (col.columnType === 'date') {
|
|
134896
134893
|
const generator = new generatorsMap.GenerateDate[0]();
|
|
134897
134894
|
return generator;
|
|
134898
134895
|
}
|
|
@@ -134900,7 +134897,7 @@ class SeedService {
|
|
|
134900
134897
|
const generator = new generatorsMap.GenerateTime[0]();
|
|
134901
134898
|
return generator;
|
|
134902
134899
|
}
|
|
134903
|
-
if (col.columnType.
|
|
134900
|
+
if (col.columnType.match(/^timestamp(\(\d\))?$/) !== null) {
|
|
134904
134901
|
const generator = new generatorsMap.GenerateTimestamp[0]();
|
|
134905
134902
|
return generator;
|
|
134906
134903
|
}
|
|
@@ -134953,7 +134950,8 @@ class SeedService {
|
|
|
134953
134950
|
return generator;
|
|
134954
134951
|
}
|
|
134955
134952
|
// number section ------------------------------------------------------------------------------------
|
|
134956
|
-
if (col.columnType.
|
|
134953
|
+
if (col.columnType.match(/^real(\(\d+,? *\d*\))?$/) !== null
|
|
134954
|
+
|| col.columnType.match(/^numeric(\(\d+,? *\d*\))?$/) !== null) {
|
|
134957
134955
|
if (col.typeParams.precision !== undefined) {
|
|
134958
134956
|
const precision = col.typeParams.precision;
|
|
134959
134957
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -135187,6 +135185,9 @@ class SeedService {
|
|
|
135187
135185
|
columnsNumber += 1;
|
|
135188
135186
|
columnGenerator = tableGenerators[columnName];
|
|
135189
135187
|
override = tableGenerators[columnName]?.generatedIdentityType === 'always' ? true : override;
|
|
135188
|
+
if (tableName === 'evaluations' && columnName === 'gameId') {
|
|
135189
|
+
console.log();
|
|
135190
|
+
}
|
|
135190
135191
|
columnsGenerators[columnName] = columnGenerator.generator;
|
|
135191
135192
|
columnsGenerators[columnName].init({
|
|
135192
135193
|
count,
|
|
@@ -135502,6 +135503,10 @@ const seedFunc = async (db, schema, options = {}, refinements) => {
|
|
|
135502
135503
|
* @example
|
|
135503
135504
|
* ```ts
|
|
135504
135505
|
* await reset(db, schema);
|
|
135506
|
+
*
|
|
135507
|
+
* // Alternatively, you can provide an object containing your tables
|
|
135508
|
+
* // as the `schema` parameter when calling `reset`.
|
|
135509
|
+
* await reset(db, { users });
|
|
135505
135510
|
* ```
|
|
135506
135511
|
*/
|
|
135507
135512
|
async function reset(db, schema) {
|