kern-orm 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ilya Semenov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # kern-orm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Fully typed relational query builder for PostgreSQL with ambient transactions and single-query relation loading.
4
+
5
+ kern-orm is in early development, and the API changes between minor versions.
6
+
7
+ See the [documentation](https://ilyasemenov.github.io/kern-orm/).
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install kern-orm @kern-orm/postgres-js postgres
13
+ ```
14
+
15
+ See [Getting Started](https://ilyasemenov.github.io/kern-orm/getting-started) for the supported runtimes, TypeScript, and PostgreSQL versions.
16
+
17
+ ## Usage
18
+
19
+ Describe the tables and their relations, then load forms with their fields in one SQL statement, and insert a form with its fields in a transaction:
20
+
21
+ ```ts
22
+ import { postgresJsDriver } from "@kern-orm/postgres-js"
23
+ import { createDatabase, defineSchema, defineTable, many } from "kern-orm"
24
+ import * as t from "kern-orm/types"
25
+ import postgres from "postgres"
26
+
27
+ const form = defineTable("form", {
28
+ id: t.uuid.primaryKey().hasDefault(),
29
+ name: t.text,
30
+ published: t.boolean,
31
+ })
32
+
33
+ const field = defineTable("form_field", {
34
+ id: t.uuid.primaryKey().hasDefault(),
35
+ formId: t.uuid.columnName("form_id"),
36
+ label: t.text,
37
+ })
38
+
39
+ const schema = defineSchema({ form, field }).$relations({
40
+ form: {
41
+ fields: many(field, { from: "id", to: "formId" }),
42
+ },
43
+ })
44
+
45
+ const database = createDatabase({
46
+ driver: postgresJsDriver(postgres(process.env.DATABASE_URL!)),
47
+ })
48
+ const db = database.bind(schema)
49
+
50
+ const forms = await db.form
51
+ .where({ published: true })
52
+ .select("id", "name")
53
+ .select(form => ({
54
+ fields: form.fields.select("id", "label"),
55
+ }))
56
+ // forms: { id: string; name: string; fields: { id: string; label: string }[] }[]
57
+
58
+ // Queries in the callback, including in called functions, join the transaction.
59
+ await db.$transaction(async () => {
60
+ const formId = await db.form.insert({ name: "Survey", published: false }).get("id")
61
+ await db.field.insertMany([
62
+ { formId, label: "Name" },
63
+ { formId, label: "Email" },
64
+ ])
65
+ })
66
+ ```