uql-orm 0.34.1 → 0.35.0
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/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* SQL Expressions
|
|
3
3
|
*
|
|
4
4
|
* Type-safe SQL expressions for default values and other uses.
|
|
5
|
-
* Provides
|
|
5
|
+
* Provides an `expr` helper with common expressions.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* Represents a raw SQL expression (not a literal value).
|
|
@@ -18,11 +18,11 @@ export declare class SqlExpression {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Helper object for common SQL expressions.
|
|
21
|
-
* Use in migrations: `
|
|
21
|
+
* Use in migrations: `t.timestamp('createdAt').defaultValue(expr.now())`
|
|
22
22
|
*/
|
|
23
|
-
export declare const
|
|
23
|
+
export declare const expr: {
|
|
24
24
|
/**
|
|
25
|
-
* Current timestamp (
|
|
25
|
+
* Current timestamp (CURRENT_TIMESTAMP).
|
|
26
26
|
*/
|
|
27
27
|
now(): SqlExpression;
|
|
28
28
|
/**
|
|
@@ -34,23 +34,11 @@ export declare const t: {
|
|
|
34
34
|
*/
|
|
35
35
|
currentTime(): SqlExpression;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
null(): SqlExpression;
|
|
40
|
-
/**
|
|
41
|
-
* Boolean true.
|
|
42
|
-
*/
|
|
43
|
-
true(): SqlExpression;
|
|
44
|
-
/**
|
|
45
|
-
* Boolean false.
|
|
46
|
-
*/
|
|
47
|
-
false(): SqlExpression;
|
|
48
|
-
/**
|
|
49
|
-
* Generate UUID (Postgres: gen_random_uuid(), MySQL: UUID()).
|
|
37
|
+
* Generate a UUID. Postgres only - use `expr.mysqlUuid()` on MySQL/MariaDB.
|
|
50
38
|
*/
|
|
51
39
|
uuid(): SqlExpression;
|
|
52
40
|
/**
|
|
53
|
-
*
|
|
41
|
+
* Generate a UUID on MySQL/MariaDB.
|
|
54
42
|
*/
|
|
55
43
|
mysqlUuid(): SqlExpression;
|
|
56
44
|
/**
|
|
@@ -59,19 +47,11 @@ export declare const t: {
|
|
|
59
47
|
*/
|
|
60
48
|
raw(sql: string): SqlExpression;
|
|
61
49
|
/**
|
|
62
|
-
*
|
|
63
|
-
*/
|
|
64
|
-
literal(value: string): SqlExpression;
|
|
65
|
-
/**
|
|
66
|
-
* Numeric literal.
|
|
67
|
-
*/
|
|
68
|
-
number(value: number): SqlExpression;
|
|
69
|
-
/**
|
|
70
|
-
* Empty JSON object.
|
|
50
|
+
* Empty JSON object. Postgres only - the `::jsonb` cast is not portable.
|
|
71
51
|
*/
|
|
72
52
|
emptyObject(): SqlExpression;
|
|
73
53
|
/**
|
|
74
|
-
* Empty JSON array.
|
|
54
|
+
* Empty JSON array. Postgres only - the `::jsonb` cast is not portable.
|
|
75
55
|
*/
|
|
76
56
|
emptyArray(): SqlExpression;
|
|
77
57
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* SQL Expressions
|
|
3
3
|
*
|
|
4
4
|
* Type-safe SQL expressions for default values and other uses.
|
|
5
|
-
* Provides
|
|
5
|
+
* Provides an `expr` helper with common expressions.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* Represents a raw SQL expression (not a literal value).
|
|
@@ -24,11 +24,11 @@ export class SqlExpression {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Helper object for common SQL expressions.
|
|
27
|
-
* Use in migrations: `
|
|
27
|
+
* Use in migrations: `t.timestamp('createdAt').defaultValue(expr.now())`
|
|
28
28
|
*/
|
|
29
|
-
export const
|
|
29
|
+
export const expr = {
|
|
30
30
|
/**
|
|
31
|
-
* Current timestamp (
|
|
31
|
+
* Current timestamp (CURRENT_TIMESTAMP).
|
|
32
32
|
*/
|
|
33
33
|
now() {
|
|
34
34
|
return new SqlExpression('CURRENT_TIMESTAMP');
|
|
@@ -46,31 +46,13 @@ export const t = {
|
|
|
46
46
|
return new SqlExpression('CURRENT_TIME');
|
|
47
47
|
},
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
*/
|
|
51
|
-
null() {
|
|
52
|
-
return new SqlExpression('NULL');
|
|
53
|
-
},
|
|
54
|
-
/**
|
|
55
|
-
* Boolean true.
|
|
56
|
-
*/
|
|
57
|
-
true() {
|
|
58
|
-
return new SqlExpression('TRUE');
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
* Boolean false.
|
|
62
|
-
*/
|
|
63
|
-
false() {
|
|
64
|
-
return new SqlExpression('FALSE');
|
|
65
|
-
},
|
|
66
|
-
/**
|
|
67
|
-
* Generate UUID (Postgres: gen_random_uuid(), MySQL: UUID()).
|
|
49
|
+
* Generate a UUID. Postgres only - use `expr.mysqlUuid()` on MySQL/MariaDB.
|
|
68
50
|
*/
|
|
69
51
|
uuid() {
|
|
70
52
|
return new SqlExpression('gen_random_uuid()');
|
|
71
53
|
},
|
|
72
54
|
/**
|
|
73
|
-
*
|
|
55
|
+
* Generate a UUID on MySQL/MariaDB.
|
|
74
56
|
*/
|
|
75
57
|
mysqlUuid() {
|
|
76
58
|
return new SqlExpression('UUID()');
|
|
@@ -83,27 +65,13 @@ export const t = {
|
|
|
83
65
|
return new SqlExpression(sql);
|
|
84
66
|
},
|
|
85
67
|
/**
|
|
86
|
-
*
|
|
87
|
-
*/
|
|
88
|
-
literal(value) {
|
|
89
|
-
// Escape single quotes by doubling them
|
|
90
|
-
const escaped = value.replace(/'/g, "''");
|
|
91
|
-
return new SqlExpression(`'${escaped}'`);
|
|
92
|
-
},
|
|
93
|
-
/**
|
|
94
|
-
* Numeric literal.
|
|
95
|
-
*/
|
|
96
|
-
number(value) {
|
|
97
|
-
return new SqlExpression(String(value));
|
|
98
|
-
},
|
|
99
|
-
/**
|
|
100
|
-
* Empty JSON object.
|
|
68
|
+
* Empty JSON object. Postgres only - the `::jsonb` cast is not portable.
|
|
101
69
|
*/
|
|
102
70
|
emptyObject() {
|
|
103
71
|
return new SqlExpression("'{}'::jsonb");
|
|
104
72
|
},
|
|
105
73
|
/**
|
|
106
|
-
* Empty JSON array.
|
|
74
|
+
* Empty JSON array. Postgres only - the `::jsonb` cast is not portable.
|
|
107
75
|
*/
|
|
108
76
|
emptyArray() {
|
|
109
77
|
return new SqlExpression("'[]'::jsonb");
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { normalizeIndexColumn } from '../../util/index.js';
|
|
7
7
|
import { derivedIndexName } from '../../util/sql.util.js';
|
|
8
8
|
import { ColumnBuilder } from './columnBuilder.js';
|
|
9
|
-
import {
|
|
9
|
+
import { expr } from './expressions.js';
|
|
10
10
|
/**
|
|
11
11
|
* Builder for table-level foreign keys.
|
|
12
12
|
*/
|
|
@@ -137,10 +137,10 @@ export class TableBuilder {
|
|
|
137
137
|
return column;
|
|
138
138
|
}
|
|
139
139
|
createdAt() {
|
|
140
|
-
return this.add('createdAt', { category: 'timestamp' }, { defaultValue:
|
|
140
|
+
return this.add('createdAt', { category: 'timestamp' }, { defaultValue: expr.now() });
|
|
141
141
|
}
|
|
142
142
|
updatedAt() {
|
|
143
|
-
return this.add('updatedAt', { category: 'timestamp' }, { defaultValue:
|
|
143
|
+
return this.add('updatedAt', { category: 'timestamp' }, { defaultValue: expr.now() });
|
|
144
144
|
}
|
|
145
145
|
timestamps() {
|
|
146
146
|
this.createdAt();
|
|
@@ -198,10 +198,10 @@ export interface BuilderMigrationDefinition {
|
|
|
198
198
|
* ```ts
|
|
199
199
|
* export default defineBuilderMigration({
|
|
200
200
|
* async up(m) {
|
|
201
|
-
* await m.createTable('users', (
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
201
|
+
* await m.createTable('users', (t) => {
|
|
202
|
+
* t.id();
|
|
203
|
+
* t.string('email', { length: 255 }).unique();
|
|
204
|
+
* t.timestamps();
|
|
205
205
|
* });
|
|
206
206
|
* },
|
|
207
207
|
* async down(m) {
|
package/dist/migrate/migrator.js
CHANGED
|
@@ -571,10 +571,10 @@ export function defineMigration(migration) {
|
|
|
571
571
|
* ```ts
|
|
572
572
|
* export default defineBuilderMigration({
|
|
573
573
|
* async up(m) {
|
|
574
|
-
* await m.createTable('users', (
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
574
|
+
* await m.createTable('users', (t) => {
|
|
575
|
+
* t.id();
|
|
576
|
+
* t.string('email', { length: 255 }).unique();
|
|
577
|
+
* t.timestamps();
|
|
578
578
|
* });
|
|
579
579
|
* },
|
|
580
580
|
* async down(m) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uql-orm",
|
|
3
3
|
"homepage": "https://uql-orm.dev",
|
|
4
|
-
"description": "JSON-native
|
|
4
|
+
"description": "JSON-native ORM for Node.js, Bun and Deno. Supports PostgreSQL, PGlite, MySQL, MariaDB, SQLite, CockroachDB, Turso, Neon, Cloudflare D1 and MongoDB. Queries are plain JSON, typed to the leaf.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.35.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=24"
|