uql-orm 0.91.1 → 0.92.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/dist/browser/http/bus.js +3 -4
- package/dist/browser/http/http.d.ts +1 -2
- package/dist/browser/http/http.js +8 -7
- package/dist/browser/index.d.ts +0 -1
- package/dist/browser/index.js +0 -1
- package/dist/browser/querier/httpQuerier.d.ts +18 -20
- package/dist/browser/querier/httpQuerier.js +20 -56
- package/dist/browser/type/index.d.ts +0 -1
- package/dist/browser/type/index.js +0 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +11 -12
- package/dist/cockroachdb/cockroachDialect.d.ts +4 -1
- package/dist/cockroachdb/cockroachDialect.js +5 -1
- package/dist/dialect/abstractDialect.d.ts +1 -1
- package/dist/dialect/abstractDialect.js +4 -1
- package/dist/dialect/abstractSqlDialect.d.ts +24 -28
- package/dist/dialect/abstractSqlDialect.js +47 -45
- package/dist/dialect/aliases.d.ts +4 -1
- package/dist/dialect/aliases.js +5 -2
- package/dist/dialect/hydrateColumn.js +3 -10
- package/dist/dialect/jsonSql.d.ts +4 -1
- package/dist/dialect/jsonSql.js +4 -1
- package/dist/dialect/mergeSqlDialect.d.ts +4 -3
- package/dist/dialect/mergeSqlDialect.js +5 -4
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +7 -21
- package/dist/dialect/mysqlLikeSqlDialect.js +9 -36
- package/dist/dialect/pgLikeSqlDialect.d.ts +3 -7
- package/dist/dialect/pgLikeSqlDialect.js +11 -21
- package/dist/http/contract.d.ts +4 -0
- package/dist/http/contract.js +1 -0
- package/dist/http/handler.d.ts +2 -2
- package/dist/http/handler.js +17 -19
- package/dist/http/query.d.ts +5 -3
- package/dist/http/query.js +42 -42
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/maria/mariaDialect.d.ts +2 -3
- package/dist/maria/mariaDialect.js +1 -5
- package/dist/migrate/builder/columnBuilder.d.ts +5 -15
- package/dist/migrate/builder/columnBuilder.js +50 -86
- package/dist/migrate/builder/expressions.d.ts +12 -18
- package/dist/migrate/builder/expressions.js +39 -42
- package/dist/migrate/builder/migrationBuilder.d.ts +3 -11
- package/dist/migrate/builder/migrationBuilder.js +41 -81
- package/dist/migrate/builder/tableBuilder.d.ts +0 -7
- package/dist/migrate/builder/tableBuilder.js +17 -28
- package/dist/migrate/builder/types.d.ts +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +3 -3
- package/dist/migrate/codegen/entityTypes.js +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.js +27 -12
- package/dist/migrate/codegen/indexDecoratorSource.js +64 -41
- package/dist/migrate/ddl/index.d.ts +2 -4
- package/dist/migrate/ddl/index.js +14 -5
- package/dist/migrate/ddl/mssqlTableDdl.d.ts +1 -0
- package/dist/migrate/ddl/mssqlTableDdl.js +4 -1
- package/dist/migrate/ddl/mysqlTableDdl.d.ts +17 -0
- package/dist/migrate/ddl/mysqlTableDdl.js +33 -0
- package/dist/migrate/ddl/pgTableDdl.d.ts +7 -0
- package/dist/migrate/ddl/pgTableDdl.js +17 -0
- package/dist/migrate/ddl/tableDdl.d.ts +15 -10
- package/dist/migrate/ddl/tableDdl.js +31 -32
- package/dist/migrate/drift/driftDetector.js +46 -59
- package/dist/migrate/generator/definitionToNode.d.ts +11 -7
- package/dist/migrate/generator/definitionToNode.js +27 -34
- package/dist/migrate/generator/indexNodeToSchema.d.ts +3 -3
- package/dist/migrate/generator/indexNodeToSchema.js +5 -4
- package/dist/migrate/index.js +1 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +10 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +10 -0
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
- package/dist/migrate/introspection/baseSqlIntrospector.js +6 -8
- package/dist/migrate/introspection/mssqlIntrospector.js +3 -8
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -4
- package/dist/migrate/introspection/mysqlIntrospector.js +25 -11
- package/dist/migrate/introspection/postgresIntrospector.d.ts +2 -2
- package/dist/migrate/introspection/postgresIntrospector.js +3 -3
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/sqliteIntrospector.js +7 -10
- package/dist/migrate/migrationTarget.js +3 -3
- package/dist/migrate/schemaGenerator.d.ts +8 -12
- package/dist/migrate/schemaGenerator.js +35 -61
- package/dist/migrate/triggerSql.d.ts +1 -1
- package/dist/migrate/triggerSql.js +8 -6
- package/dist/mongo/mongoDialect.d.ts +4 -3
- package/dist/mongo/mongoDialect.js +52 -38
- package/dist/mongo/mongoIntrospector.js +1 -1
- package/dist/mongo/mongoSchemaGenerator.d.ts +7 -4
- package/dist/mongo/mongoSchemaGenerator.js +18 -21
- package/dist/mongo/mongodbQuerier.d.ts +2 -3
- package/dist/mongo/mongodbQuerier.js +9 -28
- package/dist/mssql/mssqlDialect.d.ts +4 -5
- package/dist/mssql/mssqlDialect.js +9 -7
- package/dist/postgres/postgresDialect.js +2 -2
- package/dist/querier/abstractQuerier.d.ts +16 -11
- package/dist/querier/abstractQuerier.js +74 -26
- package/dist/querier/abstractQuerierPool.d.ts +26 -24
- package/dist/querier/abstractQuerierPool.js +26 -64
- package/dist/querier/abstractSqlQuerier.d.ts +2 -3
- package/dist/querier/abstractSqlQuerier.js +8 -26
- package/dist/querier/cursor.d.ts +10 -0
- package/dist/querier/cursor.js +81 -0
- package/dist/querier/keyset.d.ts +19 -0
- package/dist/querier/keyset.js +198 -0
- package/dist/schema/canonicalType.d.ts +3 -3
- package/dist/schema/canonicalType.js +13 -12
- package/dist/schema/indexDifferences.d.ts +14 -7
- package/dist/schema/indexDifferences.js +7 -5
- package/dist/schema/schemaAST.d.ts +0 -1
- package/dist/schema/schemaAST.js +0 -2
- package/dist/schema/schemaASTBuilder.js +28 -20
- package/dist/schema/schemaASTDiffer.d.ts +7 -9
- package/dist/schema/schemaASTDiffer.js +54 -107
- package/dist/schema/sqlExpression.d.ts +22 -0
- package/dist/schema/sqlExpression.js +28 -0
- package/dist/schema/types.d.ts +48 -105
- package/dist/sqlite/sqliteDialect.d.ts +9 -13
- package/dist/sqlite/sqliteDialect.js +10 -29
- package/dist/type/dialect.d.ts +20 -3
- package/dist/type/entity.d.ts +3 -3
- package/dist/type/migration.d.ts +7 -7
- package/dist/type/querier.d.ts +19 -26
- package/dist/type/query.d.ts +104 -24
- package/dist/type/query.js +21 -28
- package/dist/type/universalQuerier.d.ts +31 -5
- package/dist/type/utility.d.ts +10 -0
- package/dist/util/bytes.d.ts +7 -0
- package/dist/util/bytes.js +22 -0
- package/dist/util/date.d.ts +5 -0
- package/dist/util/date.js +5 -0
- package/dist/util/dialect.util.d.ts +1 -25
- package/dist/util/dialect.util.js +4 -50
- package/dist/util/field.util.d.ts +9 -0
- package/dist/util/field.util.js +15 -0
- package/dist/util/fieldOption.util.js +2 -2
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/util/object.util.d.ts +0 -2
- package/dist/util/object.util.js +0 -7
- package/dist/util/query.util.d.ts +40 -0
- package/dist/util/query.util.js +76 -0
- package/dist/util/raw.d.ts +5 -0
- package/dist/util/raw.js +5 -0
- package/dist/util/relationQuery.util.js +18 -16
- package/dist/util/rowKey.util.js +2 -3
- package/dist/util/sql.util.d.ts +8 -2
- package/dist/util/sql.util.js +16 -17
- package/dist/util/sqlLiteral.js +2 -12
- package/dist/util/string.util.d.ts +5 -0
- package/dist/util/string.util.js +12 -0
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +21 -10
- package/dist/browser/options.d.ts +0 -4
- package/dist/browser/options.js +0 -13
- package/dist/browser/type/clientQuerierPool.d.ts +0 -4
- package/dist/browser/type/clientQuerierPool.js +0 -1
package/skills/uql-orm/SKILL.md
CHANGED
|
@@ -74,18 +74,20 @@ export class Post {
|
|
|
74
74
|
}
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
- Every `@Field` states its `type
|
|
77
|
+
- Every `@Field` states its `type`: `String`, `Number`, `Boolean`, `Date`, `BigInt`, or a column type such as `'uuid'`, `'text'`, `'jsonb'`. A foreign key takes `references` instead and inherits the target key's type. A `Date` is an instant, stored in UTC to the millisecond on every engine; `precision` sets other fractional digits.
|
|
78
78
|
- A column is nullable unless it says `nullable: false`, and its property must admit `null` to match: `title?: string | null`. A property typed without `| null` on a nullable column is a compile error.
|
|
79
79
|
- Declare a `nullable: false` column `!` (`email!: string`): reads have it and inserts must name it, except a single-column key and a `version`, which uql fills. Declare `?` whatever an insert may leave out: a nullable, `onInsert`, `defaultValue`, `eager: false` or `computed` field, and relations.
|
|
80
80
|
- An engine's own column type is a `raw` constant, ``columnType: raw`tsvector` ``, rendered verbatim and carrying its own `length`/`precision`: never a bare string.
|
|
81
|
+
- `defaultValue` is a value of the field's type, or SQL the database evaluates per row: `currentTimestamp` or ``raw`gen_random_uuid()` ``. A string is always text, `'CURRENT_TIMESTAMP'` included.
|
|
82
|
+
- `currentTimestamp` is the database clock, UTC to the millisecond on every engine, where a raw `CURRENT_TIMESTAMP` is not on SQLite, MySQL or SQL Server. Use it for a default, a stamp, `onUpdate` or `$where`.
|
|
81
83
|
- Members are named by callbacks, never by strings: `mappedBy: (post) => post.author`, `references: (post) => post.authorId`.
|
|
82
84
|
- `@ManyToMany({ entity: () => Tag, through: () => PostTag })` names its junction entity.
|
|
83
85
|
- `@Index((post) => [post.authorId], { where: { archived: { $ne: true } } })` states a partial index's filter as the predicate the query passes, never as `raw`: a planner matches the two by shape, so `raw` that means the same thing leaves the index unused.
|
|
84
86
|
- `@Field({ type: Number, version: true })`, with `[versionKey]?: 'version'` on the class, is an optimistic lock:
|
|
85
87
|
an update must carry the version it read (a compile error otherwise), and one against a row someone else moved on throws `UqlOptimisticLockError` (kind `optimisticLock`, HTTP 409). Its updates name one row by its id; save and upsert are refused.
|
|
86
88
|
- `@Field({ computed })` is a value the database produces, on a `readonly` property: SQL over the row, ``(u) => raw`${u.first} || ' ' || ${u.last}` ``, or a relation aggregate, `(order) => order.items.count()`.
|
|
87
|
-
`stored: true` makes the SQL a generated column; `stored: ['insert', 'update']` makes it a stamp, a trigger
|
|
88
|
-
- `@Trigger({ on: 'afterUpdate', of: (post) => [post.status], where: { $old: { status: 'draft' } }, run })` is a trigger the database fires
|
|
89
|
+
`stored: true` makes the SQL a generated column; `stored: ['insert', 'update']` makes it a stamp, which a trigger writes on those events whoever writes the row (`computed: currentTimestamp`), where `onUpdate` covers only uql's own writes.
|
|
90
|
+
- `@Trigger({ on: 'afterUpdate', of: (post) => [post.status], where: { $old: { status: 'draft' } }, run })` is a trigger the database fires. `run(newRow, oldRow)` returns the body, written with `insertInto`, `updateTable` and `deleteFrom`, which are typed by the entity written and render on every engine; anything else is `raw` SQL over the rows, per engine where they differ. A trigger's writes skip uql's fills and entity filters, soft delete included. MongoDB has none. Details, SQL Server's per-statement shape included: https://uql-orm.dev/entities/triggers.md
|
|
89
91
|
- `defineEntity` defines the same entity without decorators: https://uql-orm.dev/entities/imperative.md
|
|
90
92
|
|
|
91
93
|
## Queries
|
|
@@ -108,8 +110,12 @@ const users = await pool.findMany(User, {
|
|
|
108
110
|
`$count: { posts: true }` tallies a to-many under `_count` without loading it.
|
|
109
111
|
- `$sort` takes `'asc'`/`1` or `'desc'`/`-1`, and `'ascNullsLast'`, `'ascNullsFirst'`, `'descNullsFirst'` or
|
|
110
112
|
`'descNullsLast'` to say where nulls land, which reads the same on every engine (emulated where there is no
|
|
111
|
-
`NULLS FIRST`). Unqualified, each engine keeps its own answer: Postgres
|
|
112
|
-
|
|
113
|
+
`NULLS FIRST`). Unqualified, each engine keeps its own answer: Postgres sorts nulls last on `asc`, the rest sort them first.
|
|
114
|
+
- `findManyPage(User, { $sort: { createdAt: -1, id: 1 }, $limit: 20, $after })` pages by cursor, so page 1,000
|
|
115
|
+
costs what page 1 does, and answers `{ items, startCursor, endCursor, hasNextPage, hasPrevPage }`: pass
|
|
116
|
+
`endCursor` as `$after`, or `startCursor` as `$before` to go back. `$sort` must include the key or a unique
|
|
117
|
+
`nullable: false` field, uses the entity's own fields, and takes no `$skip`. A nullable leading sort key pages
|
|
118
|
+
correctly but cannot use an index.
|
|
113
119
|
- `$where` takes a value for equality or an operator map: `$eq`, `$ne`, `$lt`, `$lte`, `$gt`, `$gte`, `$in`,
|
|
114
120
|
`$nin`, `$between`, `$like`, `$ilike`, `$regex`, `$startsWith`, `$endsWith`, `$includes`, `$isNull`,
|
|
115
121
|
`$isNotNull`. `$and`, `$or`, `$not` and `$nor` combine clauses.
|
|
@@ -122,7 +128,7 @@ const users = await pool.findMany(User, {
|
|
|
122
128
|
- `$populate` loads relations in the same statement. Nothing is lazy: a relation not populated is not there.
|
|
123
129
|
- A query is plain data, so it can be built dynamically, stored, or sent from a browser to `uql-orm/http`,
|
|
124
130
|
whose handler serves only the entities its required `include` names.
|
|
125
|
-
- Methods: `findMany`, `findOne`, `findOneById`, `findManyAndCount`, `findManyStream`, `count`, `exists`,
|
|
131
|
+
- Methods: `findMany`, `findOne`, `findOneById`, `findManyAndCount`, `findManyPage`, `findManyStream`, `count`, `exists`,
|
|
126
132
|
`aggregate`, `insertOne`, `insertMany`, `updateOneById`, `updateMany`, `saveOne`, `saveMany`, `upsertOne`,
|
|
127
133
|
`upsertMany`, `deleteOneById`, `deleteMany`. Each takes the entity class first.
|
|
128
134
|
- `updateMany` and `deleteMany` naming no rows - no `$where` holding a value (an `undefined` or an empty group holds none), no `$limit` - throw; `{ unfiltered: true }` means the whole table.
|
|
@@ -154,10 +160,15 @@ transaction. A querier from `pool.getQuerier()` is yours to release: bind it wit
|
|
|
154
160
|
|
|
155
161
|
## Migrations
|
|
156
162
|
|
|
157
|
-
`npx uql-migrate` reads `uql.config.ts
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
`npx uql-migrate` reads `uql.config.ts`:
|
|
164
|
+
|
|
165
|
+
- `sync` applies what the entities imply (development only).
|
|
166
|
+
- `generate:entities` writes the diff as a migration file to review. It renames a column whose field was renamed and refuses a required column with no default on a table holding rows.
|
|
167
|
+
- `up` and `down` apply and revert migrations.
|
|
168
|
+
- `generate:from-db` writes entity classes from an existing database.
|
|
169
|
+
- `drift:check` fails when the database no longer matches.
|
|
170
|
+
|
|
171
|
+
Triggers are part of the diff: uql owns the `_uql_`-prefixed ones and never touches another.
|
|
161
172
|
|
|
162
173
|
## Where to read more
|
|
163
174
|
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ClientQuerier, ClientQuerierPool } from './type/index.js';
|
|
2
|
-
export declare function setQuerierPool<T extends ClientQuerierPool>(pool: T): void;
|
|
3
|
-
export declare function getQuerierPool(): ClientQuerierPool;
|
|
4
|
-
export declare function getQuerier(): ClientQuerier;
|
package/dist/browser/options.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { HttpQuerier } from './querier/httpQuerier.js';
|
|
2
|
-
let defaultPool = {
|
|
3
|
-
getQuerier: () => new HttpQuerier('/api'),
|
|
4
|
-
};
|
|
5
|
-
export function setQuerierPool(pool) {
|
|
6
|
-
defaultPool = pool;
|
|
7
|
-
}
|
|
8
|
-
export function getQuerierPool() {
|
|
9
|
-
return defaultPool;
|
|
10
|
-
}
|
|
11
|
-
export function getQuerier() {
|
|
12
|
-
return getQuerierPool().getQuerier();
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|