@forinda/kickjs-db 5.1.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 +21 -0
- package/README.md +66 -0
- package/dist/index.d.mts +786 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1793 -0
- package/dist/index.mjs.map +1 -0
- package/dist/pg.d.mts +53 -0
- package/dist/pg.d.mts.map +1 -0
- package/dist/pg.mjs +55 -0
- package/dist/pg.mjs.map +1 -0
- package/dist/types-BcfY4esK.mjs +106 -0
- package/dist/types-BcfY4esK.mjs.map +1 -0
- package/dist/types-D2FzsPow.d.mts +162 -0
- package/dist/types-D2FzsPow.d.mts.map +1 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Felix Orinda
|
|
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
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @forinda/kickjs-db
|
|
2
|
+
|
|
3
|
+
> KickJS-native ORM — code-first schema, reversible migrations, multi-dialect SQL.
|
|
4
|
+
|
|
5
|
+
Phantom-typed column builders, `SchemaToKysely<S>` for end-to-end row inference, `KickDbRegister` module augmentation, runtime lifecycle hooks (`query` / `queryError` / `slowQuery`), `customType` mapper, `pgEnum` with full migration pipeline, and `db.$extends({ model })` per-table methods.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @forinda/kickjs-db
|
|
11
|
+
pnpm add @forinda/kickjs-db-pg pg # PostgreSQL adapter
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { table, uuid, varchar, timestamp, createDbClient } from '@forinda/kickjs-db'
|
|
18
|
+
import { pgAdapter, pgDialect } from '@forinda/kickjs-db-pg'
|
|
19
|
+
import { Pool } from 'pg'
|
|
20
|
+
|
|
21
|
+
// 1. Schema — phantom T flows through every column automatically.
|
|
22
|
+
const users = table('users', {
|
|
23
|
+
id: uuid().primaryKey().defaultRandom(),
|
|
24
|
+
email: varchar(255).notNull().unique(),
|
|
25
|
+
createdAt: timestamp().notNull().defaultNow(),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const schema = { users }
|
|
29
|
+
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
|
30
|
+
|
|
31
|
+
// 2. Client — DB shape inferred from schema, no manual generic.
|
|
32
|
+
const db = createDbClient({
|
|
33
|
+
schema,
|
|
34
|
+
dialect: pgDialect({ pool }),
|
|
35
|
+
events: true,
|
|
36
|
+
slowQueryThresholdMs: 100,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
db.on('slowQuery', ({ sql, durationMs }) => {
|
|
40
|
+
console.warn({ sql, durationMs }, 'slow query')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// 3. Query — fully typed against the schema.
|
|
44
|
+
const row = await db
|
|
45
|
+
.selectFrom('users')
|
|
46
|
+
.selectAll()
|
|
47
|
+
.where('email', '=', 'a@b.com')
|
|
48
|
+
.executeTakeFirst()
|
|
49
|
+
// row?.email is string; row?.createdAt is Date
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Docs
|
|
53
|
+
|
|
54
|
+
- [Schema Types](https://forinda.github.io/kick-js/guide/db-schema-types) — phantom inference, `KickDbRegister`, self-references, `pgEnum`
|
|
55
|
+
- [DB Extensions](https://forinda.github.io/kick-js/guide/db-extensions) — `customType<T>()`, `$extends({ model })`
|
|
56
|
+
- [Type Generation](https://forinda.github.io/kick-js/guide/typegen) — `kick typegen` plugin contract + `kick/db` auto-emit
|
|
57
|
+
|
|
58
|
+
## Companion packages
|
|
59
|
+
|
|
60
|
+
- [`@forinda/kickjs-db-pg`](https://www.npmjs.com/package/@forinda/kickjs-db-pg) — node-postgres adapter
|
|
61
|
+
- [`@forinda/kickjs`](https://www.npmjs.com/package/@forinda/kickjs) — framework runtime + DI container
|
|
62
|
+
- [`@forinda/kickjs-cli`](https://www.npmjs.com/package/@forinda/kickjs-cli) — `kick db generate`, `kick db migrate`, `kick typegen`
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT © Felix Orinda
|