@type32/tauri-sqlite-orm 0.2.13 → 0.3.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/README.md +14 -8
- package/dist/index.d.mts +359 -176
- package/dist/index.d.ts +359 -176
- package/dist/index.js +868 -851
- package/dist/index.mjs +868 -848
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A Drizzle-like TypeScript ORM tailored for Tauri v2's `@tauri-apps/plugin-sql` (
|
|
|
7
7
|
- **Drizzle-like Schema:** Define your database schema using a familiar, chainable API.
|
|
8
8
|
- **Strict Type Inference:** Full TypeScript type safety with no `any` types - nullable columns, custom types, and required/optional fields are accurately inferred.
|
|
9
9
|
- **Type-Safe Query Builder:** Build SQL queries with TypeScript, ensuring type safety and autocompletion.
|
|
10
|
-
- **Relations Support:** Define and query one-to-one, one-to-many, and many-to-many relationships between tables.
|
|
10
|
+
- **Relations Support:** Define and query one-to-one, one-to-many, and many-to-many (via junction tables, Drizzle-style) relationships between tables.
|
|
11
11
|
- **Nested Includes:** Load relations of relations with intuitive nested syntax.
|
|
12
12
|
- **Advanced Operators:** Comprehensive set of operators including `ne`, `between`, `notIn`, `ilike`, `startsWith`, `endsWith`, `contains`, and more.
|
|
13
13
|
- **Subquery Support:** Use subqueries in WHERE and SELECT clauses with full type safety.
|
|
@@ -16,6 +16,7 @@ A Drizzle-like TypeScript ORM tailored for Tauri v2's `@tauri-apps/plugin-sql` (
|
|
|
16
16
|
- **Safety Features:** Automatic WHERE clause validation for UPDATE/DELETE prevents accidental data loss.
|
|
17
17
|
- **Increment/Decrement:** Atomic increment/decrement operations for safe counter updates.
|
|
18
18
|
- **Better Error Handling:** Custom error classes for clear, actionable error messages.
|
|
19
|
+
- **Cascade Actions:** `onDelete` and `onUpdate` (cascade, set null, set default, restrict, no action) for foreign key references.
|
|
19
20
|
- **Simplified Migrations:** Keep your database schema in sync with your application's models using automatic schema detection and migration tools.
|
|
20
21
|
- **Lightweight & Performant:** Designed to be a thin layer over the Tauri SQL plugin, ensuring minimal overhead.
|
|
21
22
|
|
|
@@ -33,20 +34,20 @@ Make sure the SQL plugin is registered on the Rust side (see Tauri docs).
|
|
|
33
34
|
|
|
34
35
|
```typescript
|
|
35
36
|
import Database from '@tauri-apps/plugin-sql'
|
|
36
|
-
import { TauriORM, sqliteTable,
|
|
37
|
+
import { TauriORM, sqliteTable, integer, text, relations, InferSelectModel, InferRelationalSelectModel } from '@type32/tauri-sqlite-orm'
|
|
37
38
|
|
|
38
39
|
// Define tables
|
|
39
40
|
const users = sqliteTable('users', {
|
|
40
|
-
id:
|
|
41
|
+
id: integer('id').primaryKey().autoincrement(),
|
|
41
42
|
name: text('name').notNull(),
|
|
42
43
|
email: text('email').notNull().unique(),
|
|
43
44
|
})
|
|
44
45
|
|
|
45
46
|
const posts = sqliteTable('posts', {
|
|
46
|
-
id:
|
|
47
|
+
id: integer('id').primaryKey().autoincrement(),
|
|
47
48
|
title: text('title').notNull(),
|
|
48
49
|
content: text('content').notNull(),
|
|
49
|
-
userId:
|
|
50
|
+
userId: integer('user_id').notNull().references(users, users._.columns.id, { onDelete: 'cascade' }),
|
|
50
51
|
})
|
|
51
52
|
|
|
52
53
|
// Define relations
|
|
@@ -78,6 +79,11 @@ const usersWithPosts = await orm
|
|
|
78
79
|
.select(users)
|
|
79
80
|
.include({ posts: true })
|
|
80
81
|
.all()
|
|
82
|
+
|
|
83
|
+
// Type relational results with InferRelationalSelectModel
|
|
84
|
+
type User = InferSelectModel<typeof users>
|
|
85
|
+
const withPosts = { posts: true } as const
|
|
86
|
+
type UserWithPosts = InferRelationalSelectModel<typeof users, typeof usersRelations, typeof withPosts>
|
|
81
87
|
```
|
|
82
88
|
|
|
83
89
|
### Documentation
|
|
@@ -88,10 +94,10 @@ const usersWithPosts = await orm
|
|
|
88
94
|
|
|
89
95
|
### Relations
|
|
90
96
|
|
|
91
|
-
The ORM supports
|
|
97
|
+
The ORM supports relations in a Drizzle-style pattern:
|
|
92
98
|
|
|
93
|
-
1. **One-to-One / Many-to-One**: Use `one()` to define a relation where the current table references another table
|
|
99
|
+
1. **One-to-One / Many-to-One**: Use `one()` with `fields` and `references` to define a relation where the current table references another table
|
|
94
100
|
2. **One-to-Many**: Use `many()` to define a relation where another table references the current table
|
|
95
|
-
3. **Many-to-Many**: Use `
|
|
101
|
+
3. **Many-to-Many**: Use `many(junctionTable)` on both sides and define `one()` on the junction with `fields`/`references` to each entity. Load with nested includes: `include({ postTags: { with: { tag: true } } })`
|
|
96
102
|
|
|
97
103
|
See the [many-to-many example](./docs/many-to-many-example.md) for detailed usage.
|