Skip to content

Commit 0badf91

Browse files
authored
fix: misc fixes (#30)
1 parent 6cd7e2e commit 0badf91

File tree

15 files changed

+46
-17
lines changed

15 files changed

+46
-17
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ For SQLite:
100100

101101
```bash
102102
npm install better-sqlite3
103+
npm install -D @types/better-sqlite3
103104
```
104105

105106
For Postgres:
106107

107108
```bash
108-
npm install pg
109+
npm install pg pg-connection-string
110+
npm install -D @types/pg
109111
```
110112

111113
## Pushing schema to the database
@@ -132,14 +134,32 @@ A `schema.ts` file will be created inside the `zenstack` folder. The file should
132134

133135
## Creating ZenStack client
134136

135-
Now you can use the compiled TypeScript schema to instantiate a database client:
137+
Now you can use the compiled TypeScript schema to instantiate a database client.
138+
139+
### SQLite
136140

137141
```ts
138142
import { ZenStackClient } from '@zenstackhq/runtime';
139143
import { schema } from './zenstack/schema';
144+
import SQLite from 'better-sqlite3';
140145

141146
const client = new ZenStackClient(schema, {
142-
dialectConfig: { ... }
147+
dialectConfig: { database: new SQLite('./dev.db') },
148+
});
149+
```
150+
151+
### Postgres
152+
153+
```ts
154+
import { ZenStackClient } from '@zenstackhq/runtime';
155+
import { schema } from './zenstack/schema';
156+
import { Pool } from 'pg';
157+
import { parseIntoClientConfig } from 'pg-connection-string';
158+
159+
const client = new ZenStackClient(schema, {
160+
dialectConfig: {
161+
pool: new Pool(parseIntoClientConfig(process.env.DATABASE_URL)),
162+
},
143163
});
144164
```
145165

@@ -376,6 +396,7 @@ See [Prisma Migrate](https://www.prisma.io/docs/orm/prisma-migrate) documentatio
376396
377397
# Limitations
378398
379-
1. Only SQLite (better-sqlite3) and Postgres (pg) database providers are supported.
399+
1. Only SQLite (better-sqlite3) and Postgres (pg) database providers are supported for now.
380400
1. Prisma client extensions are not supported.
381401
1. Prisma custom generators are not supported (may add support in the future).
402+
1. [Filtering on JSON fields](https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types/working-with-json-fields#filter-on-a-json-field-advanced) is not supported yet.

TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- [x] generate
77
- [x] migrate
88
- [x] info
9-
- [ ] init
9+
- [x] init
1010
- [ ] ORM
1111
- [x] Create
1212
- [x] Input validation
@@ -36,6 +36,7 @@
3636
- [x] Sorting
3737
- [x] Pagination
3838
- [x] Distinct
39+
- [ ] JSON filtering
3940
- [x] Update
4041
- [x] Input validation
4142
- [x] Top-level
@@ -65,7 +66,6 @@
6566
- [ ] Error system
6667
- [x] Custom table name
6768
- [x] Custom field name
68-
- [ ] Strict undefined check
6969
- [ ] Implement changesets
7070
- [ ] Polymorphism
7171
- [ ] Validation

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-v3",
3-
"version": "3.0.0-alpha.2",
3+
"version": "3.0.0-alpha.4",
44
"description": "ZenStack",
55
"packageManager": "[email protected]",
66
"scripts": {

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "zenstack",
44
"displayName": "ZenStack CLI",
55
"description": "FullStack database toolkit with built-in access control and automatic API generation.",
6-
"version": "3.0.0-alpha.2",
6+
"version": "3.0.0-alpha.4",
77
"type": "module",
88
"author": {
99
"name": "ZenStack Team"

packages/create-zenstack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-zenstack",
3-
"version": "3.0.0-alpha.2",
3+
"version": "3.0.0-alpha.4",
44
"description": "Create a new ZenStack project",
55
"type": "module",
66
"scripts": {

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/language",
33
"description": "ZenStack ZModel language specification",
4-
"version": "3.0.0-alpha.2",
4+
"version": "3.0.0-alpha.4",
55
"license": "MIT",
66
"author": "ZenStack Team",
77
"files": [

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/runtime",
3-
"version": "3.0.0-alpha.2",
3+
"version": "3.0.0-alpha.4",
44
"description": "ZenStack Runtime",
55
"type": "module",
66
"scripts": {

packages/runtime/src/client/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type { ToKyselySchema } from './query-builder';
2424
type DialectConfig<Provider extends DataSourceProvider> =
2525
Provider['type'] extends 'sqlite'
2626
? Optional<SqliteDialectConfig, 'database'>
27-
: Provider extends 'postgresql'
27+
: Provider['type'] extends 'postgresql'
2828
? Optional<PostgresDialectConfig, 'pool'>
2929
: never;
3030

packages/runtime/test/client-api/filter.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,13 @@ describe.each(createClientSpecs(PG_DB_NAME))(
549549
).toResolveTruthy();
550550
});
551551

552+
it('ignores undefined filters', async () => {
553+
await createUser();
554+
await expect(
555+
client.user.findMany({ where: { id: undefined } })
556+
).toResolveWithLength(1);
557+
});
558+
552559
// TODO: filter for bigint, decimal, bytes
553560
}
554561
);

packages/runtime/test/client-api/find.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe.each(createClientSpecs(PG_DB_NAME))(
3030
r = await client.user.findMany();
3131
expect(r).toHaveLength(1);
3232
expect(r[0]?.createdAt).toBeInstanceOf(Date);
33+
3334
r = await client.user.findMany({ where: { id: user.id } });
3435
expect(r).toHaveLength(1);
3536

0 commit comments

Comments
 (0)