rado 1.0.4 → 1.0.5
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/dist/core/Column.d.ts +5 -2
- package/dist/core/Column.js +12 -5
- package/dist/core/Emitter.js +1 -1
- package/dist/core/query/Insert.js +3 -3
- package/dist/postgres/diff.js +3 -3
- package/dist/sqlite/diff.js +2 -2
- package/package.json +1 -1
package/dist/core/Column.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ export interface ColumnData {
|
|
|
11
11
|
notNull?: boolean;
|
|
12
12
|
isUnique?: boolean;
|
|
13
13
|
autoIncrement?: boolean;
|
|
14
|
-
|
|
14
|
+
$default?(): Sql;
|
|
15
|
+
defaultValue?: Sql;
|
|
15
16
|
references?(): FieldData;
|
|
16
17
|
onUpdate?: Sql;
|
|
17
18
|
onDelete?: Sql;
|
|
@@ -23,7 +24,9 @@ export declare class Column<Value = unknown> {
|
|
|
23
24
|
readonly [internalData]: ColumnData;
|
|
24
25
|
constructor(data: ColumnData);
|
|
25
26
|
notNull(): RequiredColumn<Value>;
|
|
26
|
-
|
|
27
|
+
$defaultFn(value: () => Input<WithoutNull<Value>>): Column<WithoutNull<Value>>;
|
|
28
|
+
$default(value: Input<WithoutNull<Value>> | (() => Input<WithoutNull<Value>>)): Column<WithoutNull<Value>>;
|
|
29
|
+
default(value: Input<WithoutNull<Value>>): Column<WithoutNull<Value>>;
|
|
27
30
|
defaultNow(): Column<WithoutNull<Value>>;
|
|
28
31
|
primaryKey(): Column<WithoutNull<Value>>;
|
|
29
32
|
unique(name?: string): Column<Value>;
|
package/dist/core/Column.js
CHANGED
|
@@ -13,20 +13,27 @@ var Column = class _Column {
|
|
|
13
13
|
notNull: true
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
$defaultFn(value) {
|
|
17
|
+
return this.$default(value);
|
|
18
|
+
}
|
|
19
|
+
$default(value) {
|
|
17
20
|
return new _Column({
|
|
18
21
|
...getData(this),
|
|
19
|
-
|
|
22
|
+
$default() {
|
|
20
23
|
return input(value instanceof Function ? value() : value);
|
|
21
24
|
}
|
|
22
25
|
});
|
|
23
26
|
}
|
|
27
|
+
default(value) {
|
|
28
|
+
return new _Column({
|
|
29
|
+
...getData(this),
|
|
30
|
+
defaultValue: input(value)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
24
33
|
defaultNow() {
|
|
25
34
|
return new _Column({
|
|
26
35
|
...getData(this),
|
|
27
|
-
defaultValue()
|
|
28
|
-
return sql.unsafe("now()");
|
|
29
|
-
}
|
|
36
|
+
defaultValue: sql.unsafe("now()")
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
39
|
primaryKey() {
|
package/dist/core/Emitter.js
CHANGED
|
@@ -65,7 +65,7 @@ var Emitter = class {
|
|
|
65
65
|
column.notNull && sql`not null`,
|
|
66
66
|
column.isUnique && sql`unique`,
|
|
67
67
|
column.autoIncrement && sql`autoincrement`,
|
|
68
|
-
column.defaultValue && sql`default ${column.defaultValue
|
|
68
|
+
column.defaultValue && sql`default ${column.defaultValue}`,
|
|
69
69
|
column.references && sql`references ${sql.chunk("emitReferences", [column.references()])}`,
|
|
70
70
|
column.onUpdate && sql`on update ${column.onUpdate}`
|
|
71
71
|
]).emitTo(this);
|
|
@@ -84,11 +84,11 @@ var InsertInto = class {
|
|
|
84
84
|
return sql`(${sql.join(
|
|
85
85
|
Object.entries(table.columns).map(([key, column]) => {
|
|
86
86
|
const value = row[key];
|
|
87
|
-
const {
|
|
87
|
+
const { $default, mapToDriverValue } = getData(column);
|
|
88
88
|
if (value !== void 0)
|
|
89
89
|
return input(mapToDriverValue?.(value) ?? value);
|
|
90
|
-
if (
|
|
91
|
-
return
|
|
90
|
+
if ($default)
|
|
91
|
+
return $default();
|
|
92
92
|
return defaultKeyword;
|
|
93
93
|
}),
|
|
94
94
|
sql`, `
|
package/dist/postgres/diff.js
CHANGED
|
@@ -113,7 +113,7 @@ var postgresDiff = (hasTable) => {
|
|
|
113
113
|
{
|
|
114
114
|
type: sql.unsafe(column2.type.toLowerCase()),
|
|
115
115
|
notNull: column2.notNull,
|
|
116
|
-
defaultValue: column2.defaultValue ?
|
|
116
|
+
defaultValue: column2.defaultValue ? sql.unsafe(column2.defaultValue) : void 0
|
|
117
117
|
}
|
|
118
118
|
];
|
|
119
119
|
})
|
|
@@ -168,8 +168,8 @@ var postgresDiff = (hasTable) => {
|
|
|
168
168
|
})
|
|
169
169
|
);
|
|
170
170
|
}
|
|
171
|
-
const localDefault = localInstruction.defaultValue
|
|
172
|
-
const schemaDefault = schemaInstruction.defaultValue
|
|
171
|
+
const localDefault = localInstruction.defaultValue;
|
|
172
|
+
const schemaDefault = schemaInstruction.defaultValue;
|
|
173
173
|
const localDefaultStr = localDefault && inline(localDefault);
|
|
174
174
|
const schemaDefaultStr = schemaDefault && inline(schemaDefault);
|
|
175
175
|
if (localDefaultStr !== schemaDefaultStr) {
|
package/dist/sqlite/diff.js
CHANGED
|
@@ -41,7 +41,7 @@ var sqliteDiff = (hasTable) => {
|
|
|
41
41
|
type: sql.unsafe(column2.type.toLowerCase()),
|
|
42
42
|
notNull: column2.notnull,
|
|
43
43
|
primary: hasSinglePrimaryKey && column2.pk === 1,
|
|
44
|
-
defaultValue: column2.dflt_value !== null ?
|
|
44
|
+
defaultValue: column2.dflt_value !== null ? sql.unsafe(column2.dflt_value) : void 0
|
|
45
45
|
})
|
|
46
46
|
)
|
|
47
47
|
];
|
|
@@ -142,7 +142,7 @@ var sqliteDiff = (hasTable) => {
|
|
|
142
142
|
);
|
|
143
143
|
const selection = { ...hasTable };
|
|
144
144
|
for (const name of missingColumns) {
|
|
145
|
-
selection[name] = getData(tableApi.columns[name]).defaultValue
|
|
145
|
+
selection[name] = getData(tableApi.columns[name]).defaultValue ?? sql`null`;
|
|
146
146
|
}
|
|
147
147
|
return [
|
|
148
148
|
// Create a new temporary table with the new definition
|