kysely-schema 0.1.0 → 0.1.2
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 +116 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# kysely-schema
|
|
2
|
+
|
|
3
|
+
> Schema-first development tool for Kysely — **Prisma's DX + Kysely's power + Zero runtime overhead**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/kysely-schema)
|
|
6
|
+
[](https://github.com/guntur-d/kysely-schema/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
## ⚠️ Development Status
|
|
9
|
+
|
|
10
|
+
This package is in early development and undergoing active testing.
|
|
11
|
+
Expect breaking changes between minor versions. Not recommended for
|
|
12
|
+
production use yet.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- 📝 **Schema-first** — Define your database schema in TypeScript
|
|
17
|
+
- 🔄 **Auto-migrations** — Generate Kysely migration files from schema changes
|
|
18
|
+
- 🎯 **Type-safe** — Auto-generate TypeScript types for your Kysely queries
|
|
19
|
+
- 🪶 **Lightweight** — Zero runtime overhead, pure code generation
|
|
20
|
+
- 💪 **Full SQL control** — Generates standard Kysely schema builder code
|
|
21
|
+
- 🔌 **Works with Kysely** — Complements existing Kysely migrations, doesn't replace them
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Install
|
|
27
|
+
npm install -D kysely-schema-cli
|
|
28
|
+
# or
|
|
29
|
+
pnpm add -D kysely-schema-cli
|
|
30
|
+
|
|
31
|
+
# Initialize (installs kysely + db driver for you)
|
|
32
|
+
npx kysely-schema init
|
|
33
|
+
# or
|
|
34
|
+
npx kys init
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Define your schema in `schema/index.ts`:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { defineSchema, table, column } from 'kysely-schema';
|
|
41
|
+
|
|
42
|
+
export default defineSchema({
|
|
43
|
+
user: table({
|
|
44
|
+
id: column.serial().primaryKey(),
|
|
45
|
+
email: column.text().notNull().unique(),
|
|
46
|
+
name: column.text().nullable(),
|
|
47
|
+
createdAt: column.timestamp().default('now()').notNull(),
|
|
48
|
+
}),
|
|
49
|
+
|
|
50
|
+
post: table({
|
|
51
|
+
id: column.serial().primaryKey(),
|
|
52
|
+
title: column.text().notNull(),
|
|
53
|
+
content: column.text().nullable(),
|
|
54
|
+
authorId: column.integer().notNull().references('user', 'id').onDelete('cascade'),
|
|
55
|
+
createdAt: column.timestamp().default('now()').notNull(),
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Generate migrations and types:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Generate a Kysely migration
|
|
64
|
+
npx kysely-schema generate-migration "initial"
|
|
65
|
+
# or
|
|
66
|
+
npx kys gm "initial"
|
|
67
|
+
|
|
68
|
+
# Generate TypeScript types
|
|
69
|
+
npx kysely-schema generate-types
|
|
70
|
+
# or
|
|
71
|
+
npx kys gt
|
|
72
|
+
|
|
73
|
+
# Run migration (standard Kysely)
|
|
74
|
+
npx kysely migrate:latest
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## CLI Commands
|
|
78
|
+
|
|
79
|
+
| Command | Alias | Description |
|
|
80
|
+
|---------|-------|-------------|
|
|
81
|
+
| `init` | — | Scaffold config, schema, migrations, and generated dirs |
|
|
82
|
+
| `generate-migration <name>` | `gm` | Generate a Kysely migration file from your schema |
|
|
83
|
+
| `generate-types` | `gt` | Generate TypeScript `Database` interface |
|
|
84
|
+
| `diff` | — | Show schema changes since last migration |
|
|
85
|
+
| `validate` | — | Validate your schema definition |
|
|
86
|
+
| `dev` | — | Watch schema, auto-regenerate types, validate, and show diffs |
|
|
87
|
+
|
|
88
|
+
## Comparison
|
|
89
|
+
|
|
90
|
+
| Feature | Prisma | kysely-codegen | **kysely-schema** |
|
|
91
|
+
|---------|--------|----------------|-------------------|
|
|
92
|
+
| Schema-first | ✅ | ❌ | ✅ |
|
|
93
|
+
| Lightweight | ❌ | ✅ | ✅ |
|
|
94
|
+
| Full SQL control | ❌ | ✅ | ✅ |
|
|
95
|
+
| Auto-migrations | ✅ | ❌ | ✅ |
|
|
96
|
+
| Type generation | ✅ | ✅ | ✅ |
|
|
97
|
+
| Runtime overhead | Heavy | None | **None** |
|
|
98
|
+
|
|
99
|
+
## Documentation
|
|
100
|
+
|
|
101
|
+
- [Getting Started](https://github.com/guntur-d/kysely-schema/blob/main/docs/getting-started.md)
|
|
102
|
+
- [Schema Definition](https://github.com/guntur-d/kysely-schema/blob/main/docs/schema-definition.md)
|
|
103
|
+
- [Migrations](https://github.com/guntur-d/kysely-schema/blob/main/docs/migrations.md)
|
|
104
|
+
- [API Reference](https://github.com/guntur-d/kysely-schema/blob/main/docs/api-reference.md)
|
|
105
|
+
|
|
106
|
+
## Contributing
|
|
107
|
+
|
|
108
|
+
This project is open source and we welcome contributions!
|
|
109
|
+
|
|
110
|
+
- 🐛 **Report bugs**: [GitHub Issues](https://github.com/guntur-d/kysely-schema/issues)
|
|
111
|
+
- 💡 **Feature requests**: [GitHub Discussions](https://github.com/guntur-d/kysely-schema/discussions)
|
|
112
|
+
- 🔀 **Pull requests**: [GitHub Repository](https://github.com/guntur-d/kysely-schema)
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
[MIT](https://github.com/guntur-d/kysely-schema/blob/main/LICENSE)
|