drizzle-seed 0.3.2-97009ae → 0.3.2-f8a2f3c
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 +213 -50
- package/index.cjs.map +1 -1
- package/index.d.cts +20 -2
- package/index.d.mts +20 -2
- package/index.d.ts +20 -2
- package/index.mjs +213 -51
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/services/GeneratorFuncs.d.cts +30 -6
- package/services/GeneratorFuncs.d.mts +30 -6
- package/services/GeneratorFuncs.d.ts +30 -6
- package/services/Generators.d.cts +27 -0
- package/services/Generators.d.mts +27 -0
- package/services/Generators.d.ts +27 -0
- package/services/utils.d.cts +1 -0
- package/services/utils.d.mts +1 -0
- package/services/utils.d.ts +1 -0
- package/types/seedService.d.cts +1 -1
- package/types/seedService.d.mts +1 -1
- package/types/seedService.d.ts +1 -1
package/index.cjs
CHANGED
|
@@ -131216,6 +131216,9 @@ const isObject = (value) => {
|
|
|
131216
131216
|
const equalSets = (set1, set2) => {
|
|
131217
131217
|
return set1.size === set2.size && [...set1].every((si) => set2.has(si));
|
|
131218
131218
|
};
|
|
131219
|
+
const isValidDate = (date) => {
|
|
131220
|
+
return !Number.isNaN(date.getTime());
|
|
131221
|
+
};
|
|
131219
131222
|
|
|
131220
131223
|
/* eslint-disable drizzle-internal/require-entity-kind */
|
|
131221
131224
|
class AbstractGenerator {
|
|
@@ -131787,13 +131790,20 @@ class GenerateDate extends AbstractGenerator {
|
|
|
131787
131790
|
const rng = prand.xoroshiro128plus(seed);
|
|
131788
131791
|
let { minDate, maxDate } = this.params;
|
|
131789
131792
|
const anchorDate = new Date('2024-05-08');
|
|
131793
|
+
// 4 years in milliseconds
|
|
131790
131794
|
const deltaMilliseconds = 4 * 31536000000;
|
|
131791
131795
|
if (typeof minDate === 'string') {
|
|
131792
131796
|
minDate = new Date(minDate);
|
|
131793
131797
|
}
|
|
131798
|
+
if (typeof minDate === 'object' && !isValidDate(minDate)) {
|
|
131799
|
+
throw new Error('Invalid Date was provided for the minDate parameter.');
|
|
131800
|
+
}
|
|
131794
131801
|
if (typeof maxDate === 'string') {
|
|
131795
131802
|
maxDate = new Date(maxDate);
|
|
131796
131803
|
}
|
|
131804
|
+
if (typeof maxDate === 'object' && !isValidDate(maxDate)) {
|
|
131805
|
+
throw new Error('Invalid Date was provided for the maxDate parameter.');
|
|
131806
|
+
}
|
|
131797
131807
|
if (minDate === undefined) {
|
|
131798
131808
|
if (maxDate === undefined) {
|
|
131799
131809
|
minDate = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
@@ -131806,6 +131816,9 @@ class GenerateDate extends AbstractGenerator {
|
|
|
131806
131816
|
if (maxDate === undefined) {
|
|
131807
131817
|
maxDate = new Date(minDate.getTime() + (2 * deltaMilliseconds));
|
|
131808
131818
|
}
|
|
131819
|
+
if (minDate > maxDate) {
|
|
131820
|
+
throw new Error(`The minDate parameter must be less than or equal to the maxDate parameter.`);
|
|
131821
|
+
}
|
|
131809
131822
|
this.state = { rng, minDate, maxDate };
|
|
131810
131823
|
}
|
|
131811
131824
|
generate() {
|
|
@@ -131827,18 +131840,83 @@ class GenerateTime extends AbstractGenerator {
|
|
|
131827
131840
|
init({ count, seed }) {
|
|
131828
131841
|
super.init({ count, seed });
|
|
131829
131842
|
const rng = prand.xoroshiro128plus(seed);
|
|
131830
|
-
|
|
131843
|
+
let { minTime, maxTime } = this.params;
|
|
131844
|
+
if (minTime === undefined && maxTime === undefined) {
|
|
131845
|
+
// TODO: maybe need to change in major version release
|
|
131846
|
+
// This is required to ensure that this generator remains deterministic when used without minTime, maxTime parameters.
|
|
131847
|
+
const oneDayInMilliseconds = 86400000;
|
|
131848
|
+
minTime = new Date(new Date('2024-05-08T12:00:00.000Z').getTime() - oneDayInMilliseconds);
|
|
131849
|
+
maxTime = new Date(new Date('2024-05-08T12:00:00.000Z').getTime() + oneDayInMilliseconds);
|
|
131850
|
+
this.state = { rng, minTime, maxTime };
|
|
131851
|
+
return;
|
|
131852
|
+
}
|
|
131853
|
+
if (minTime === undefined) {
|
|
131854
|
+
if (maxTime === undefined) {
|
|
131855
|
+
minTime = '00:00:00.000Z';
|
|
131856
|
+
maxTime = '23:59:59.999Z';
|
|
131857
|
+
}
|
|
131858
|
+
else {
|
|
131859
|
+
minTime = '00:00:00.000Z';
|
|
131860
|
+
}
|
|
131861
|
+
}
|
|
131862
|
+
if (maxTime === undefined) {
|
|
131863
|
+
maxTime = '23:59:59.999Z';
|
|
131864
|
+
new Date().toISOString();
|
|
131865
|
+
}
|
|
131866
|
+
const anchorDate = new Date('2024-05-08');
|
|
131867
|
+
const anchorDateString0 = anchorDate.toISOString().replace(/T\d{2}:\d{2}:\d{2}.\d{3}Z/, '');
|
|
131868
|
+
if (typeof minTime === 'string') {
|
|
131869
|
+
// const timeMatch0 = minTime.match(/^\d{2}:\d{2}:\d{2}.\d{1,3}Z?$/);
|
|
131870
|
+
const timeMatch1 = minTime.match(/^\d{2}:\d{2}:\d{2}Z?$/);
|
|
131871
|
+
const timeMatch2 = minTime.match(/^\d{2}:\d{2}Z?$/);
|
|
131872
|
+
if (
|
|
131873
|
+
// timeMatch0 === null
|
|
131874
|
+
timeMatch1 === null
|
|
131875
|
+
&& timeMatch2 === null) {
|
|
131876
|
+
throw new Error(`You're using the wrong format for the minTime parameter.`
|
|
131877
|
+
+ `\nPlease use one of these formats: 'HH:mm:ss', 'HH:mm' (with or without a trailing 'Z')`);
|
|
131878
|
+
}
|
|
131879
|
+
minTime = minTime.at(-1) === 'Z' ? minTime : minTime + 'Z';
|
|
131880
|
+
minTime = new Date(anchorDate.toISOString().replace(/\d{2}:\d{2}:\d{2}.\d{3}Z/, minTime));
|
|
131881
|
+
}
|
|
131882
|
+
if (typeof minTime === 'object') {
|
|
131883
|
+
if (!isValidDate(minTime)) {
|
|
131884
|
+
throw new Error('Invalid Date was provided for the minTime parameter.');
|
|
131885
|
+
}
|
|
131886
|
+
minTime = new Date(minTime.toISOString().replace(/\d{4}-\d{2}-\d{2}/, anchorDateString0));
|
|
131887
|
+
}
|
|
131888
|
+
if (typeof maxTime === 'string') {
|
|
131889
|
+
// const timeMatch0 = maxTime.match(/^\d{2}:\d{2}:\d{2}.\d{1,3}Z?$/);
|
|
131890
|
+
const timeMatch1 = maxTime.match(/^\d{2}:\d{2}:\d{2}Z?$/);
|
|
131891
|
+
const timeMatch2 = maxTime.match(/^\d{2}:\d{2}Z?$/);
|
|
131892
|
+
if (
|
|
131893
|
+
// timeMatch0 === null
|
|
131894
|
+
timeMatch1 === null
|
|
131895
|
+
&& timeMatch2 === null) {
|
|
131896
|
+
throw new Error(`You're using the wrong format for the maxTime parameter.`
|
|
131897
|
+
+ `\nPlease use one of these formats: 'HH:mm:ss', 'HH:mm' (with or without a trailing 'Z').`);
|
|
131898
|
+
}
|
|
131899
|
+
maxTime = maxTime.at(-1) === 'Z' ? maxTime : maxTime + 'Z';
|
|
131900
|
+
maxTime = new Date(anchorDate.toISOString().replace(/\d{2}:\d{2}:\d{2}.\d{3}Z/, maxTime));
|
|
131901
|
+
}
|
|
131902
|
+
if (typeof maxTime === 'object') {
|
|
131903
|
+
if (!isValidDate(maxTime)) {
|
|
131904
|
+
throw new Error('Invalid Date was provided for the maxTime parameter.');
|
|
131905
|
+
}
|
|
131906
|
+
maxTime = new Date(maxTime.toISOString().replace(/\d{4}-\d{2}-\d{2}/, anchorDateString0));
|
|
131907
|
+
}
|
|
131908
|
+
if (minTime > maxTime) {
|
|
131909
|
+
throw new Error(`The minTime parameter must be less than or equal to the maxTime parameter.`);
|
|
131910
|
+
}
|
|
131911
|
+
this.state = { rng, minTime, maxTime };
|
|
131831
131912
|
}
|
|
131832
131913
|
generate() {
|
|
131833
131914
|
if (this.state === undefined) {
|
|
131834
131915
|
throw new Error('state is not defined.');
|
|
131835
131916
|
}
|
|
131836
|
-
const anchorDateTime = new Date('2024-05-08T12:00:00.000Z');
|
|
131837
|
-
const oneDayInMilliseconds = 86400000;
|
|
131838
|
-
let date = new Date();
|
|
131839
131917
|
let milliseconds;
|
|
131840
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
131841
|
-
date = new Date(
|
|
131918
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minTime.getTime(), this.state.maxTime.getTime(), this.state.rng);
|
|
131919
|
+
const date = new Date(milliseconds);
|
|
131842
131920
|
return date.toISOString().replace(/(\d{4}-\d{2}-\d{2}T)|(\.\d{3}Z)/g, '');
|
|
131843
131921
|
}
|
|
131844
131922
|
}
|
|
@@ -131848,18 +131926,46 @@ class GenerateTimestamp extends AbstractGenerator {
|
|
|
131848
131926
|
init({ count, seed }) {
|
|
131849
131927
|
super.init({ count, seed });
|
|
131850
131928
|
const rng = prand.xoroshiro128plus(seed);
|
|
131851
|
-
|
|
131929
|
+
let { minTimestamp, maxTimestamp } = this.params;
|
|
131930
|
+
const anchorDate = new Date('2024-05-08');
|
|
131931
|
+
// 2 years in milliseconds
|
|
131932
|
+
const deltaMilliseconds = 2 * 31536000000;
|
|
131933
|
+
if (typeof minTimestamp === 'string') {
|
|
131934
|
+
minTimestamp = new Date(minTimestamp);
|
|
131935
|
+
}
|
|
131936
|
+
if (typeof minTimestamp === 'object' && !isValidDate(minTimestamp)) {
|
|
131937
|
+
throw new Error('Invalid Date was provided for the minTimestamp parameter.');
|
|
131938
|
+
}
|
|
131939
|
+
if (typeof maxTimestamp === 'string') {
|
|
131940
|
+
maxTimestamp = new Date(maxTimestamp);
|
|
131941
|
+
}
|
|
131942
|
+
if (typeof maxTimestamp === 'object' && !isValidDate(maxTimestamp)) {
|
|
131943
|
+
throw new Error('Invalid Date was provided for the maxTimestamp parameter.');
|
|
131944
|
+
}
|
|
131945
|
+
if (minTimestamp === undefined) {
|
|
131946
|
+
if (maxTimestamp === undefined) {
|
|
131947
|
+
minTimestamp = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
131948
|
+
maxTimestamp = new Date(anchorDate.getTime() + deltaMilliseconds);
|
|
131949
|
+
}
|
|
131950
|
+
else {
|
|
131951
|
+
minTimestamp = new Date(maxTimestamp.getTime() - (2 * deltaMilliseconds));
|
|
131952
|
+
}
|
|
131953
|
+
}
|
|
131954
|
+
if (maxTimestamp === undefined) {
|
|
131955
|
+
maxTimestamp = new Date(minTimestamp.getTime() + (2 * deltaMilliseconds));
|
|
131956
|
+
}
|
|
131957
|
+
if (minTimestamp > maxTimestamp) {
|
|
131958
|
+
throw new Error(`The minTimestamp parameter must be less than or equal to the maxTimestamp parameter.`);
|
|
131959
|
+
}
|
|
131960
|
+
this.state = { rng, minTimestamp, maxTimestamp };
|
|
131852
131961
|
}
|
|
131853
131962
|
generate() {
|
|
131854
131963
|
if (this.state === undefined) {
|
|
131855
131964
|
throw new Error('state is not defined.');
|
|
131856
131965
|
}
|
|
131857
|
-
const anchorTimestamp = new Date('2024-05-08');
|
|
131858
|
-
const twoYearsInMilliseconds = 2 * 31536000000;
|
|
131859
|
-
let date = new Date();
|
|
131860
131966
|
let milliseconds;
|
|
131861
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
131862
|
-
date = new Date(
|
|
131967
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minTimestamp.getTime(), this.state.maxTimestamp.getTime(), this.state.rng);
|
|
131968
|
+
const date = new Date(milliseconds);
|
|
131863
131969
|
if (this.dataType === 'string') {
|
|
131864
131970
|
return date
|
|
131865
131971
|
.toISOString()
|
|
@@ -131875,18 +131981,46 @@ class GenerateDatetime extends AbstractGenerator {
|
|
|
131875
131981
|
init({ count, seed }) {
|
|
131876
131982
|
super.init({ count, seed });
|
|
131877
131983
|
const rng = prand.xoroshiro128plus(seed);
|
|
131878
|
-
|
|
131984
|
+
let { minDatetime, maxDatetime } = this.params;
|
|
131985
|
+
const anchorDate = new Date('2024-05-08');
|
|
131986
|
+
// 2 years in milliseconds
|
|
131987
|
+
const deltaMilliseconds = 2 * 31536000000;
|
|
131988
|
+
if (typeof minDatetime === 'string') {
|
|
131989
|
+
minDatetime = new Date(minDatetime);
|
|
131990
|
+
}
|
|
131991
|
+
if (typeof minDatetime === 'object' && !isValidDate(minDatetime)) {
|
|
131992
|
+
throw new Error('Invalid Date was provided for the minDatetime parameter.');
|
|
131993
|
+
}
|
|
131994
|
+
if (typeof maxDatetime === 'string') {
|
|
131995
|
+
maxDatetime = new Date(maxDatetime);
|
|
131996
|
+
}
|
|
131997
|
+
if (typeof maxDatetime === 'object' && !isValidDate(maxDatetime)) {
|
|
131998
|
+
throw new Error('Invalid Date was provided for the maxDatetime parameter.');
|
|
131999
|
+
}
|
|
132000
|
+
if (minDatetime === undefined) {
|
|
132001
|
+
if (maxDatetime === undefined) {
|
|
132002
|
+
minDatetime = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
132003
|
+
maxDatetime = new Date(anchorDate.getTime() + deltaMilliseconds);
|
|
132004
|
+
}
|
|
132005
|
+
else {
|
|
132006
|
+
minDatetime = new Date(maxDatetime.getTime() - (2 * deltaMilliseconds));
|
|
132007
|
+
}
|
|
132008
|
+
}
|
|
132009
|
+
if (maxDatetime === undefined) {
|
|
132010
|
+
maxDatetime = new Date(minDatetime.getTime() + (2 * deltaMilliseconds));
|
|
132011
|
+
}
|
|
132012
|
+
if (minDatetime > maxDatetime) {
|
|
132013
|
+
throw new Error(`The minDatetime parameter must be less than or equal to the maxDatetime parameter.`);
|
|
132014
|
+
}
|
|
132015
|
+
this.state = { rng, minDatetime, maxDatetime };
|
|
131879
132016
|
}
|
|
131880
132017
|
generate() {
|
|
131881
132018
|
if (this.state === undefined) {
|
|
131882
132019
|
throw new Error('state is not defined.');
|
|
131883
132020
|
}
|
|
131884
|
-
const anchorDate = new Date('2024-05-08');
|
|
131885
|
-
const twoYearsInMilliseconds = 2 * 31536000000;
|
|
131886
|
-
let date = new Date();
|
|
131887
132021
|
let milliseconds;
|
|
131888
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
131889
|
-
date = new Date(
|
|
132022
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minDatetime.getTime(), this.state.maxDatetime.getTime(), this.state.rng);
|
|
132023
|
+
const date = new Date(milliseconds);
|
|
131890
132024
|
if (this.dataType === 'string') {
|
|
131891
132025
|
return date
|
|
131892
132026
|
.toISOString()
|
|
@@ -133559,6 +133693,8 @@ const generatorsFuncs = {
|
|
|
133559
133693
|
date: createGenerator(GenerateDate),
|
|
133560
133694
|
/**
|
|
133561
133695
|
* generates time in 24 hours style.
|
|
133696
|
+
* @param minTime - lower border of range.
|
|
133697
|
+
* @param maxTime - upper border of range.
|
|
133562
133698
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
133563
133699
|
*
|
|
133564
133700
|
* @example
|
|
@@ -133566,7 +133702,7 @@ const generatorsFuncs = {
|
|
|
133566
133702
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
133567
133703
|
* users: {
|
|
133568
133704
|
* columns: {
|
|
133569
|
-
* birthTime: funcs.time()
|
|
133705
|
+
* birthTime: funcs.time({ minTime: "11:12:13.141", maxTime: "15:16:17.181" })
|
|
133570
133706
|
* },
|
|
133571
133707
|
* },
|
|
133572
133708
|
* }));
|
|
@@ -133576,6 +133712,8 @@ const generatorsFuncs = {
|
|
|
133576
133712
|
time: createGenerator(GenerateTime),
|
|
133577
133713
|
/**
|
|
133578
133714
|
* generates timestamps.
|
|
133715
|
+
* @param minTimestamp - lower border of range.
|
|
133716
|
+
* @param maxTimestamp - upper border of range.
|
|
133579
133717
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
133580
133718
|
*
|
|
133581
133719
|
* @example
|
|
@@ -133583,7 +133721,7 @@ const generatorsFuncs = {
|
|
|
133583
133721
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
133584
133722
|
* orders: {
|
|
133585
133723
|
* columns: {
|
|
133586
|
-
* shippedDate: funcs.timestamp()
|
|
133724
|
+
* shippedDate: funcs.timestamp({ minTimestamp: "2025-03-07T11:12:13.141", maxTimestamp: "2025-03-08T15:16:17.181" })
|
|
133587
133725
|
* },
|
|
133588
133726
|
* },
|
|
133589
133727
|
* }));
|
|
@@ -133593,6 +133731,8 @@ const generatorsFuncs = {
|
|
|
133593
133731
|
timestamp: createGenerator(GenerateTimestamp),
|
|
133594
133732
|
/**
|
|
133595
133733
|
* generates datetime objects.
|
|
133734
|
+
* @param minDatetime - lower border of range.
|
|
133735
|
+
* @param maxDatetime - upper border of range.
|
|
133596
133736
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
133597
133737
|
*
|
|
133598
133738
|
* @example
|
|
@@ -133600,7 +133740,7 @@ const generatorsFuncs = {
|
|
|
133600
133740
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
133601
133741
|
* orders: {
|
|
133602
133742
|
* columns: {
|
|
133603
|
-
* shippedDate: funcs.datetime()
|
|
133743
|
+
* shippedDate: funcs.datetime({ minDatetime: "2025-03-07T11:12:13.141", maxDatetime: "2025-03-08T15:16:17.181" })
|
|
133604
133744
|
* },
|
|
133605
133745
|
* },
|
|
133606
133746
|
* }));
|
|
@@ -134061,7 +134201,7 @@ const generatorsFuncs = {
|
|
|
134061
134201
|
*/
|
|
134062
134202
|
weightedRandom: createGenerator(WeightedRandomGenerator),
|
|
134063
134203
|
};
|
|
134064
|
-
// so far, version changes don’t
|
|
134204
|
+
// so far, version changes don’t change generator parameters.
|
|
134065
134205
|
const generatorsFuncsV2 = {
|
|
134066
134206
|
...generatorsFuncs,
|
|
134067
134207
|
};
|
|
@@ -134272,6 +134412,7 @@ class SeedService {
|
|
|
134272
134412
|
};
|
|
134273
134413
|
}
|
|
134274
134414
|
}
|
|
134415
|
+
// handling refinements (count, with)
|
|
134275
134416
|
if (refinements !== undefined && refinements[table.name] !== undefined) {
|
|
134276
134417
|
if (refinements[table.name].count !== undefined) {
|
|
134277
134418
|
tablesPossibleGenerators[i].count = refinements[table.name].count;
|
|
@@ -134332,11 +134473,24 @@ class SeedService {
|
|
|
134332
134473
|
wasDefinedBefore: false,
|
|
134333
134474
|
wasRefined: false,
|
|
134334
134475
|
};
|
|
134476
|
+
// handling refinements (columnGenerator)
|
|
134335
134477
|
if (refinements !== undefined
|
|
134336
134478
|
&& refinements[table.name] !== undefined
|
|
134337
134479
|
&& refinements[table.name].columns !== undefined
|
|
134338
134480
|
&& refinements[table.name].columns[col.name] !== undefined) {
|
|
134339
134481
|
const genObj = refinements[table.name].columns[col.name];
|
|
134482
|
+
if (genObj === false) {
|
|
134483
|
+
if (col.notNull === true && col.hasDefault === false) {
|
|
134484
|
+
throw new Error(`You cannot set the '${col.name}' column in the '${table.name}' table to false in your refinements.`
|
|
134485
|
+
+ `\nDoing so will result in a null value being inserted into the '${col.name}' column,`
|
|
134486
|
+
+ `\nwhich will cause an error because the column has a not null constraint and no default value.`);
|
|
134487
|
+
}
|
|
134488
|
+
// Generating undefined as a value for a column and then inserting it via drizzle-orm
|
|
134489
|
+
// will result in the value not being inserted into that column.
|
|
134490
|
+
columnPossibleGenerator.generator = new generatorsMap.GenerateDefault[0]({ defaultValue: undefined });
|
|
134491
|
+
columnPossibleGenerator.wasRefined = true;
|
|
134492
|
+
continue;
|
|
134493
|
+
}
|
|
134340
134494
|
if (col.columnType.match(/\[\w*]/g) !== null) {
|
|
134341
134495
|
if ((col.baseColumn?.dataType === 'array' && col.baseColumn.columnType.match(/\[\w*]/g) !== null)
|
|
134342
134496
|
// studio case
|
|
@@ -134648,8 +134802,8 @@ class SeedService {
|
|
|
134648
134802
|
// NUMBER(real, double, decimal, numeric)
|
|
134649
134803
|
if (col.columnType === 'real'
|
|
134650
134804
|
|| col.columnType === 'double precision'
|
|
134651
|
-
|| col.columnType.match(/^decimal(\(\d
|
|
134652
|
-
|| col.columnType.match(/^numeric(\(\d
|
|
134805
|
+
|| col.columnType.match(/^decimal(\(\d{1,6}(, ?-?\d{0,5})?\))?$/) !== null
|
|
134806
|
+
|| col.columnType.match(/^numeric(\(\d{1,6}(, ?-?\d{0,5})?\))?$/) !== null) {
|
|
134653
134807
|
if (col.typeParams.precision !== undefined) {
|
|
134654
134808
|
const precision = col.typeParams.precision;
|
|
134655
134809
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -134825,8 +134979,8 @@ class SeedService {
|
|
|
134825
134979
|
if (col.columnType === 'real'
|
|
134826
134980
|
|| col.columnType === 'double'
|
|
134827
134981
|
|| col.columnType === 'float'
|
|
134828
|
-
|| col.columnType.
|
|
134829
|
-
|| col.columnType.
|
|
134982
|
+
|| col.columnType.startsWith('decimal')
|
|
134983
|
+
|| col.columnType.startsWith('numeric')) {
|
|
134830
134984
|
if (col.typeParams.precision !== undefined) {
|
|
134831
134985
|
const precision = col.typeParams.precision;
|
|
134832
134986
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -134844,40 +134998,40 @@ class SeedService {
|
|
|
134844
134998
|
// STRING
|
|
134845
134999
|
if ((col.columnType === 'text'
|
|
134846
135000
|
|| col.columnType === 'blob'
|
|
134847
|
-
|| col.columnType.
|
|
134848
|
-
|| col.columnType.
|
|
134849
|
-
|| col.columnType.
|
|
134850
|
-
|| col.columnType.
|
|
135001
|
+
|| col.columnType.startsWith('char')
|
|
135002
|
+
|| col.columnType.startsWith('varchar')
|
|
135003
|
+
|| col.columnType.startsWith('binary')
|
|
135004
|
+
|| col.columnType.startsWith('varbinary'))
|
|
134851
135005
|
&& table.primaryKeys.includes(col.name)) {
|
|
134852
135006
|
const generator = new generatorsMap.GenerateUniqueString[0]();
|
|
134853
135007
|
return generator;
|
|
134854
135008
|
}
|
|
134855
135009
|
if ((col.columnType === 'text'
|
|
134856
135010
|
|| col.columnType === 'blob'
|
|
134857
|
-
|| col.columnType.
|
|
134858
|
-
|| col.columnType.
|
|
134859
|
-
|| col.columnType.
|
|
134860
|
-
|| col.columnType.
|
|
135011
|
+
|| col.columnType.startsWith('char')
|
|
135012
|
+
|| col.columnType.startsWith('varchar')
|
|
135013
|
+
|| col.columnType.startsWith('binary')
|
|
135014
|
+
|| col.columnType.startsWith('varbinary'))
|
|
134861
135015
|
&& col.name.toLowerCase().includes('name')) {
|
|
134862
135016
|
const generator = new generatorsMap.GenerateFirstName[0]();
|
|
134863
135017
|
return generator;
|
|
134864
135018
|
}
|
|
134865
135019
|
if ((col.columnType === 'text'
|
|
134866
135020
|
|| col.columnType === 'blob'
|
|
134867
|
-
|| col.columnType.
|
|
134868
|
-
|| col.columnType.
|
|
134869
|
-
|| col.columnType.
|
|
134870
|
-
|| col.columnType.
|
|
135021
|
+
|| col.columnType.startsWith('char')
|
|
135022
|
+
|| col.columnType.startsWith('varchar')
|
|
135023
|
+
|| col.columnType.startsWith('binary')
|
|
135024
|
+
|| col.columnType.startsWith('varbinary'))
|
|
134871
135025
|
&& col.name.toLowerCase().includes('email')) {
|
|
134872
135026
|
const generator = new generatorsMap.GenerateEmail[0]();
|
|
134873
135027
|
return generator;
|
|
134874
135028
|
}
|
|
134875
135029
|
if (col.columnType === 'text'
|
|
134876
135030
|
|| col.columnType === 'blob'
|
|
134877
|
-
|| col.columnType.
|
|
134878
|
-
|| col.columnType.
|
|
134879
|
-
|| col.columnType.
|
|
134880
|
-
|| col.columnType.
|
|
135031
|
+
|| col.columnType.startsWith('char')
|
|
135032
|
+
|| col.columnType.startsWith('varchar')
|
|
135033
|
+
|| col.columnType.startsWith('binary')
|
|
135034
|
+
|| col.columnType.startsWith('varbinary')) {
|
|
134881
135035
|
const generator = new generatorsMap.GenerateString[0]();
|
|
134882
135036
|
return generator;
|
|
134883
135037
|
}
|
|
@@ -134887,7 +135041,7 @@ class SeedService {
|
|
|
134887
135041
|
return generator;
|
|
134888
135042
|
}
|
|
134889
135043
|
// DATE, TIME, TIMESTAMP, DATETIME, YEAR
|
|
134890
|
-
if (col.columnType.
|
|
135044
|
+
if (col.columnType.startsWith('datetime')) {
|
|
134891
135045
|
const generator = new generatorsMap.GenerateDatetime[0]();
|
|
134892
135046
|
return generator;
|
|
134893
135047
|
}
|
|
@@ -134899,7 +135053,7 @@ class SeedService {
|
|
|
134899
135053
|
const generator = new generatorsMap.GenerateTime[0]();
|
|
134900
135054
|
return generator;
|
|
134901
135055
|
}
|
|
134902
|
-
if (col.columnType.
|
|
135056
|
+
if (col.columnType.startsWith('timestamp')) {
|
|
134903
135057
|
const generator = new generatorsMap.GenerateTimestamp[0]();
|
|
134904
135058
|
return generator;
|
|
134905
135059
|
}
|
|
@@ -134952,8 +135106,8 @@ class SeedService {
|
|
|
134952
135106
|
return generator;
|
|
134953
135107
|
}
|
|
134954
135108
|
// number section ------------------------------------------------------------------------------------
|
|
134955
|
-
if (col.columnType.
|
|
134956
|
-
|| col.columnType.
|
|
135109
|
+
if (col.columnType.startsWith('real')
|
|
135110
|
+
|| col.columnType.startsWith('numeric')) {
|
|
134957
135111
|
if (col.typeParams.precision !== undefined) {
|
|
134958
135112
|
const precision = col.typeParams.precision;
|
|
134959
135113
|
const scale = col.typeParams.scale === undefined ? 0 : col.typeParams.scale;
|
|
@@ -135187,9 +135341,6 @@ class SeedService {
|
|
|
135187
135341
|
columnsNumber += 1;
|
|
135188
135342
|
columnGenerator = tableGenerators[columnName];
|
|
135189
135343
|
override = tableGenerators[columnName]?.generatedIdentityType === 'always' ? true : override;
|
|
135190
|
-
if (tableName === 'evaluations' && columnName === 'gameId') {
|
|
135191
|
-
console.log();
|
|
135192
|
-
}
|
|
135193
135344
|
columnsGenerators[columnName] = columnGenerator.generator;
|
|
135194
135345
|
columnsGenerators[columnName].init({
|
|
135195
135346
|
count,
|
|
@@ -135422,7 +135573,7 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
135422
135573
|
* // seeding with count and seed specified
|
|
135423
135574
|
* await seed(db, schema, { count: 100000, seed: 1 });
|
|
135424
135575
|
*
|
|
135425
|
-
* //seeding using refine
|
|
135576
|
+
* // seeding using refine
|
|
135426
135577
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
135427
135578
|
* users: {
|
|
135428
135579
|
* columns: {
|
|
@@ -135443,6 +135594,17 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
135443
135594
|
* },
|
|
135444
135595
|
* }));
|
|
135445
135596
|
*
|
|
135597
|
+
* // seeding while ignoring column
|
|
135598
|
+
* await seed(db, schema).refine((funcs) => ({
|
|
135599
|
+
* users: {
|
|
135600
|
+
* count: 5,
|
|
135601
|
+
* columns: {
|
|
135602
|
+
* name: funcs.fullName(),
|
|
135603
|
+
* photo: false, // the photo column will not be seeded, allowing the database to use its default value.
|
|
135604
|
+
* },
|
|
135605
|
+
* },
|
|
135606
|
+
* }));
|
|
135607
|
+
*
|
|
135446
135608
|
* ```
|
|
135447
135609
|
*/
|
|
135448
135610
|
function seed(db, schema, options) {
|
|
@@ -136148,6 +136310,7 @@ const getSqliteInfo = (sqliteSchema, sqliteTables) => {
|
|
|
136148
136310
|
return { tables, relations: isCyclicRelations, tableRelations };
|
|
136149
136311
|
};
|
|
136150
136312
|
|
|
136313
|
+
exports.AbstractGenerator = AbstractGenerator;
|
|
136151
136314
|
exports.SeedService = SeedService;
|
|
136152
136315
|
exports.cities = cityNames;
|
|
136153
136316
|
exports.countries = countries;
|