uql-orm 0.70.0 → 0.72.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.
Files changed (78) hide show
  1. package/README.md +2 -0
  2. package/dist/browser/uql-browser.min.js +2 -2
  3. package/dist/browser/uql-browser.min.js.map +3 -3
  4. package/dist/cockroachdb/cockroachDialect.d.ts +6 -0
  5. package/dist/cockroachdb/cockroachDialect.js +8 -0
  6. package/dist/d1/d1SqliteDialect.d.ts +3 -0
  7. package/dist/d1/d1SqliteDialect.js +3 -1
  8. package/dist/dialect/abstractSqlDialect.d.ts +14 -2
  9. package/dist/dialect/abstractSqlDialect.js +48 -16
  10. package/dist/dialect/aliases.d.ts +2 -0
  11. package/dist/dialect/aliases.js +2 -0
  12. package/dist/dialect/hydrateColumn.d.ts +3 -2
  13. package/dist/dialect/hydrateColumn.js +10 -1
  14. package/dist/dialect/mysqlLikeSqlDialect.d.ts +2 -0
  15. package/dist/dialect/mysqlLikeSqlDialect.js +6 -1
  16. package/dist/dialect/pgLikeSqlDialect.d.ts +21 -5
  17. package/dist/dialect/pgLikeSqlDialect.js +48 -15
  18. package/dist/dialect/queryJoins.d.ts +14 -4
  19. package/dist/dialect/queryJoins.js +31 -11
  20. package/dist/dialect/vectorCast.d.ts +2 -0
  21. package/dist/dialect/vectorCast.js +7 -0
  22. package/dist/dialect/vectorSqlDialect.d.ts +7 -3
  23. package/dist/dialect/vectorSqlDialect.js +15 -10
  24. package/dist/libsql/libsqlDialect.d.ts +1 -1
  25. package/dist/libsql/libsqlDialect.js +3 -3
  26. package/dist/maria/mariaDialect.d.ts +3 -9
  27. package/dist/maria/mariaDialect.js +5 -15
  28. package/dist/maria/mariadbQuerier.js +9 -3
  29. package/dist/migrate/ddl/index.d.ts +1 -0
  30. package/dist/migrate/ddl/index.js +4 -2
  31. package/dist/migrate/ddl/indexDdl.d.ts +2 -0
  32. package/dist/migrate/ddl/indexDdl.js +10 -2
  33. package/dist/migrate/ddl/pgIndexDdl.d.ts +3 -4
  34. package/dist/migrate/ddl/pgIndexDdl.js +11 -11
  35. package/dist/migrate/ddl/sqliteIndexDdl.d.ts +11 -0
  36. package/dist/migrate/ddl/sqliteIndexDdl.js +38 -0
  37. package/dist/migrate/generator/mongoCommand.d.ts +28 -0
  38. package/dist/migrate/generator/mongoCommand.js +8 -0
  39. package/dist/migrate/generator/mongoSchemaGenerator.d.ts +2 -0
  40. package/dist/migrate/generator/mongoSchemaGenerator.js +50 -6
  41. package/dist/migrate/introspection/mongoIntrospector.js +33 -7
  42. package/dist/migrate/introspection/postgresIntrospector.js +19 -0
  43. package/dist/migrate/introspection/sqliteIntrospector.d.ts +6 -0
  44. package/dist/migrate/introspection/sqliteIntrospector.js +29 -3
  45. package/dist/mongo/mongoDialect.d.ts +5 -3
  46. package/dist/mongo/mongoDialect.js +40 -17
  47. package/dist/mongo/mongodbQuerier.js +4 -5
  48. package/dist/mssql/mssqlDialect.js +1 -0
  49. package/dist/schema/canonicalType.js +10 -4
  50. package/dist/schema/indexDifferences.d.ts +5 -2
  51. package/dist/schema/indexDifferences.js +5 -0
  52. package/dist/schema/schemaASTBuilder.js +3 -2
  53. package/dist/sqlite/localSqliteQuerierPool.d.ts +10 -11
  54. package/dist/sqlite/localSqliteQuerierPool.js +8 -11
  55. package/dist/sqlite/nodeSqliteQuerierPool.d.ts +4 -2
  56. package/dist/sqlite/nodeSqliteQuerierPool.js +7 -4
  57. package/dist/sqlite/sqliteDialect.d.ts +11 -1
  58. package/dist/sqlite/sqliteDialect.js +46 -3
  59. package/dist/sqlite/sqliteQuerierPool.d.ts +6 -5
  60. package/dist/sqlite/sqliteQuerierPool.js +10 -7
  61. package/dist/turso/tursoLocalDialect.d.ts +1 -1
  62. package/dist/turso/tursoLocalDialect.js +1 -1
  63. package/dist/turso/tursoLocalQuerierPool.d.ts +4 -5
  64. package/dist/turso/tursoLocalQuerierPool.js +3 -10
  65. package/dist/type/dialect.d.ts +5 -0
  66. package/dist/type/entity.d.ts +27 -13
  67. package/dist/type/migration.d.ts +7 -9
  68. package/dist/type/query.d.ts +11 -4
  69. package/dist/type/queryAggregate.d.ts +5 -16
  70. package/dist/type/utility.d.ts +13 -0
  71. package/dist/type/vector.d.ts +17 -0
  72. package/dist/type/vector.js +6 -0
  73. package/dist/util/ddlExpression.util.d.ts +2 -0
  74. package/dist/util/ddlExpression.util.js +5 -0
  75. package/dist/util/dialect.util.d.ts +21 -2
  76. package/dist/util/dialect.util.js +42 -2
  77. package/package.json +4 -3
  78. package/skills/uql-orm/SKILL.md +146 -0
@@ -0,0 +1,146 @@
1
+ ---
2
+ name: uql-orm
3
+ description: >
4
+ Write code with UQL (the uql-orm package), the TypeScript ORM whose queries are plain JSON objects,
5
+ on PostgreSQL, MySQL, MariaDB, SQLite, CockroachDB, SQL Server, MongoDB, Turso, Neon, D1 and PGlite.
6
+ Use when a project imports uql-orm, or when defining entities, querying, populating relations,
7
+ writing transactions, raw SQL or migrations with it. UQL is not Prisma, Drizzle, TypeORM or MikroORM:
8
+ their APIs do not carry over.
9
+ ---
10
+
11
+ # UQL
12
+
13
+ Entities are classes; a query is a JSON object checked key by key against the entity; the same query runs
14
+ on every database UQL supports. There is no schema file, no generated client, and no query builder.
15
+
16
+ The full docs are Markdown at https://uql-orm.dev/llms.txt, one page per URL. Read the page for the task
17
+ before guessing an option: every page listed there is a `.md` URL.
18
+
19
+ ## Setup
20
+
21
+ ```sh
22
+ npm install uql-orm pg # or mysql2, mariadb, better-sqlite3, mongodb, @libsql/client, ...
23
+ ```
24
+
25
+ ESM only. Node 24+, Bun, Deno or an edge runtime, TypeScript 5.2+. Decorators are the TC39 standard:
26
+ never enable `experimentalDecorators` or `emitDecoratorMetadata`, never import `reflect-metadata`.
27
+ In `tsconfig.json`, `module` is `nodenext` or `preserve`, and `target` is a dated one (`es2022`+), not `esnext`.
28
+
29
+ ```ts
30
+ // uql.config.ts
31
+ import type { Config } from 'uql-orm';
32
+ import { PgQuerierPool } from 'uql-orm/postgres';
33
+ import { Post, User } from './entities.js';
34
+
35
+ export const pool = new PgQuerierPool({ connectionString: process.env.DATABASE_URL });
36
+
37
+ export default { pool, entities: [User, Post] } satisfies Config;
38
+ ```
39
+
40
+ Each driver has its own entry point: `uql-orm/postgres`, `uql-orm/mysql`, `uql-orm/maria`, `uql-orm/sqlite`,
41
+ `uql-orm/mongo`, `uql-orm/libsql`, `uql-orm/turso`, `uql-orm/neon`, `uql-orm/d1`, `uql-orm/pglite`,
42
+ `uql-orm/bunSql`, `uql-orm/mssql`, `uql-orm/cockroachdb`. Build the pool once per process and import it.
43
+
44
+ ## Entities
45
+
46
+ ```ts
47
+ import { Entity, Field, Id, ManyToOne, OneToMany } from 'uql-orm';
48
+
49
+ @Entity()
50
+ export class User {
51
+ @Id({ type: 'uuid', onInsert: () => crypto.randomUUID() })
52
+ id?: string;
53
+
54
+ @Field({ type: String, unique: true, nullable: false })
55
+ email?: string;
56
+
57
+ @OneToMany({ entity: () => Post, mappedBy: (post) => post.author })
58
+ posts?: Post[];
59
+ }
60
+
61
+ @Entity()
62
+ export class Post {
63
+ @Id({ type: Number })
64
+ id?: number;
65
+
66
+ @Field({ type: String })
67
+ title?: string | null;
68
+
69
+ @Field({ references: () => User })
70
+ authorId?: string | null;
71
+
72
+ @ManyToOne({ entity: () => User, references: (post) => post.authorId })
73
+ author?: User;
74
+ }
75
+ ```
76
+
77
+ - Every `@Field` states its `type` (`String`, `Number`, `Boolean`, `Date`, `BigInt`, or a column type such as
78
+ `'uuid'`, `'text'`, `'jsonb'`), except a foreign key, which takes `references` and inherits the target key's type.
79
+ - A column is nullable unless it says `nullable: false`, and its property must admit `null` to match:
80
+ `title?: string | null`. A property typed without `| null` on a nullable column is a compile error.
81
+ - Members are named by callbacks, never by strings: `mappedBy: (post) => post.author`, `references: (post) => post.authorId`.
82
+ - `@ManyToMany({ entity: () => Tag, through: () => PostTag })` names its junction entity.
83
+ - `defineEntity` defines the same entity without decorators: https://uql-orm.dev/entities/imperative.md
84
+
85
+ ## Queries
86
+
87
+ ```ts
88
+ import { pool } from './uql.config.js';
89
+ import { User } from './entities.js';
90
+
91
+ const users = await pool.findMany(User, {
92
+ $select: { id: true, email: true },
93
+ $where: { email: { $endsWith: '@uql-orm.dev' }, $or: [{ id: 'a' }, { id: 'b' }] },
94
+ $populate: { posts: { $select: { title: true }, $sort: { id: 'desc' }, $limit: 5 } },
95
+ $sort: { email: 'asc' },
96
+ $skip: 0,
97
+ $limit: 20,
98
+ });
99
+ ```
100
+
101
+ - The keys are `$select`, `$exclude`, `$where`, `$populate`, `$count`, `$distinct`, `$sort`, `$skip`, `$limit`;
102
+ `$count: { posts: true }` tallies a to-many under `_count` without loading it.
103
+ - `$where` takes a value for equality or an operator map: `$eq`, `$ne`, `$lt`, `$lte`, `$gt`, `$gte`, `$in`,
104
+ `$nin`, `$between`, `$like`, `$ilike`, `$regex`, `$startsWith`, `$endsWith`, `$includes`, `$isNull`,
105
+ `$isNotNull`. `$and`, `$or`, `$not` and `$nor` combine clauses.
106
+ - A result is narrowed to what the query selected and populated: reading an unselected field is a compile error.
107
+ Name that shape with `QueryFindResult<User, 'id' | 'email'>` rather than widening the query.
108
+ - `$populate` loads relations in the same statement. Nothing is lazy: a relation not populated is not there.
109
+ - A query is plain data, so it can be built dynamically, stored, or sent from a browser to `uql-orm/http`.
110
+ - Methods: `findMany`, `findOne`, `findOneById`, `findManyAndCount`, `findManyStream`, `count`, `exists`,
111
+ `aggregate`, `insertOne`, `insertMany`, `updateOneById`, `updateMany`, `saveOne`, `saveMany`, `upsertOne`,
112
+ `upsertMany`, `deleteOneById`, `deleteMany`. Each takes the entity class first.
113
+ - `updateMany` and `deleteMany` naming no rows - no `$where`, no `$limit` - throw; `{ unfiltered: true }` means the whole table.
114
+ - An update takes `{ stock: { $inc: -1 } }` to add, or `$mul` to multiply, in the statement, a NULL counting as 0,
115
+ so a guard in `$where` (`stock: { $gte: 1 }`) makes a decrement race-safe. JSON fields take `$set`, `$unset`,
116
+ `$push`, `$pull`.
117
+ - `raw()` embeds SQL anywhere a value or field goes; `pool.all(sql, values)` runs a raw `SELECT`.
118
+
119
+ ## Connections and transactions
120
+
121
+ Every method is on both the pool and a querier. A pool call acquires a connection for that call and releases it.
122
+ To run several operations on one connection, or atomically, hold a querier:
123
+
124
+ ```ts
125
+ await pool.transaction(async (querier) => {
126
+ const userId = await querier.insertOne(User, { email: 'ada@uql-orm.dev' });
127
+ await querier.insertOne(Post, { title: 'Hello', authorId: userId });
128
+ });
129
+ ```
130
+
131
+ Inside the callback, call `querier`, never `pool`: a `pool` call runs on another connection, outside the
132
+ transaction. A querier from `pool.getQuerier()` is yours to release: bind it with `await using`.
133
+
134
+ ## Migrations
135
+
136
+ `npx uql-migrate` reads `uql.config.ts`. `sync` creates what the entities imply (development only);
137
+ `generate:entities` writes the diff as a migration file to review; `up` applies migrations; `generate:from-db`
138
+ writes entity classes from an existing database; `drift:check` fails when the database no longer matches.
139
+
140
+ ## Where to read more
141
+
142
+ - Operators, per-dialect SQL: https://uql-orm.dev/querying/comparison-operators.md
143
+ - Relations and deep `$populate`: https://uql-orm.dev/querying/relations.md
144
+ - Every method's signature: https://uql-orm.dev/querying/methods.md
145
+ - Coming from Prisma, Drizzle, TypeORM or MikroORM: https://uql-orm.dev/switching-to-uql.md
146
+ - Breaking changes by version: https://uql-orm.dev/upgrade-guide.md