@guren/orm 2.11.0 → 2.11.1
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 +76 -0
- package/package.json +17 -1
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @guren/orm
|
|
2
|
+
|
|
3
|
+
Eloquent-style models for [Guren](https://guren.dev/), a Bun-first fullstack TypeScript framework with Laravel-style conventions. A Model API over [Drizzle ORM](https://orm.drizzle.team/), with PostgreSQL, MySQL, SQLite, and Cloudflare D1 behind one interface.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Application code gets the Model API from [`@guren/core`](https://www.npmjs.com/package/@guren/core), which re-exports it:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @guren/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Starting a new app? Scaffold one and pick a database:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bunx create-guren-app my-app
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Defining a model
|
|
20
|
+
|
|
21
|
+
Tables are declared with Drizzle's schema DSL, re-exported per dialect so the app pins one copy of `drizzle-orm`:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// db/schema.ts
|
|
25
|
+
import { sqliteTable, integer, text } from '@guren/orm/drizzle/sqlite'
|
|
26
|
+
|
|
27
|
+
export const posts = sqliteTable('posts', {
|
|
28
|
+
id: integer('id').primaryKey({ autoIncrement: true }),
|
|
29
|
+
title: text('title').notNull(),
|
|
30
|
+
body: text('body').notNull(),
|
|
31
|
+
published: integer('published', { mode: 'boolean' }).notNull().default(false),
|
|
32
|
+
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// app/Models/Post.ts
|
|
38
|
+
import { defineModel } from '@guren/core'
|
|
39
|
+
import { posts } from '@/db/schema'
|
|
40
|
+
|
|
41
|
+
export class Post extends defineModel(posts) {
|
|
42
|
+
static fillable = ['title', 'body']
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Querying
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const post = await Post.find(1) // null when missing
|
|
50
|
+
const post = await Post.findOrFail(1) // throws ModelNotFoundException (404)
|
|
51
|
+
const published = await Post.where('published', true).orderBy('createdAt', 'desc').get()
|
|
52
|
+
const page = await Post.paginate({ page: 1, perPage: 20 })
|
|
53
|
+
const post = await Post.create({ title: 'Hello', body: 'World' })
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Relationships, scopes, soft deletes, observers, accessors and mutators, and eager loading are documented in the [database guide](https://guren.dev/docs/guides/database).
|
|
57
|
+
|
|
58
|
+
## Mass assignment
|
|
59
|
+
|
|
60
|
+
`fillable` is the allowlist, and it is always strict: primary keys are excluded, and an `AuthenticatableModel` refuses password hashes and remember tokens whatever the list says. Trusted values go through `forceCreate()` and `forceUpdate()`.
|
|
61
|
+
|
|
62
|
+
## Dialect subpaths
|
|
63
|
+
|
|
64
|
+
| Import | Contents |
|
|
65
|
+
|--------|----------|
|
|
66
|
+
| `@guren/orm/drizzle/pg` | Drizzle's PostgreSQL schema DSL, plus `sql` |
|
|
67
|
+
| `@guren/orm/drizzle/mysql` | The MySQL schema DSL |
|
|
68
|
+
| `@guren/orm/drizzle/sqlite` | The SQLite and D1 schema DSL |
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
[guren.dev/docs](https://guren.dev/docs)
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/orm",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.1",
|
|
4
|
+
"description": "Eloquent-style models for the Guren framework, on Drizzle ORM: PostgreSQL, MySQL, SQLite and Cloudflare D1.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"guren",
|
|
7
|
+
"bun",
|
|
8
|
+
"typescript",
|
|
9
|
+
"fullstack",
|
|
10
|
+
"framework",
|
|
11
|
+
"orm",
|
|
12
|
+
"drizzle",
|
|
13
|
+
"eloquent",
|
|
14
|
+
"active-record",
|
|
15
|
+
"postgres",
|
|
16
|
+
"mysql",
|
|
17
|
+
"sqlite",
|
|
18
|
+
"d1"
|
|
19
|
+
],
|
|
4
20
|
"type": "module",
|
|
5
21
|
"sideEffects": [
|
|
6
22
|
"./src/instance-guard.ts",
|