Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ For SQLite:

```bash
npm install better-sqlite3
npm install -D @types/better-sqlite3
```

For Postgres:

```bash
npm install pg
npm install pg pg-connection-string
npm install -D @types/pg
```

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

## Creating ZenStack client

Now you can use the compiled TypeScript schema to instantiate a database client:
Now you can use the compiled TypeScript schema to instantiate a database client.

### SQLite

```ts
import { ZenStackClient } from '@zenstackhq/runtime';
import { schema } from './zenstack/schema';
import SQLite from 'better-sqlite3';

const client = new ZenStackClient(schema, {
dialectConfig: { ... }
dialectConfig: { database: new SQLite('./dev.db') },
});
```

### Postgres

```ts
import { ZenStackClient } from '@zenstackhq/runtime';
import { schema } from './zenstack/schema';
import { Pool } from 'pg';
import { parseIntoClientConfig } from 'pg-connection-string';

const client = new ZenStackClient(schema, {
dialectConfig: {
pool: new Pool(parseIntoClientConfig(process.env.DATABASE_URL)),
},
});
```

Expand Down Expand Up @@ -376,6 +396,7 @@ See [Prisma Migrate](https://www.prisma.io/docs/orm/prisma-migrate) documentatio

# Limitations

1. Only SQLite (better-sqlite3) and Postgres (pg) database providers are supported.
1. Only SQLite (better-sqlite3) and Postgres (pg) database providers are supported for now.
1. Prisma client extensions are not supported.
1. Prisma custom generators are not supported (may add support in the future).
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.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- [x] generate
- [x] migrate
- [x] info
- [ ] init
- [x] init
- [ ] ORM
- [x] Create
- [x] Input validation
Expand Down Expand Up @@ -36,6 +36,7 @@
- [x] Sorting
- [x] Pagination
- [x] Distinct
- [ ] JSON filtering
- [x] Update
- [x] Input validation
- [x] Top-level
Expand Down Expand Up @@ -65,7 +66,6 @@
- [ ] Error system
- [x] Custom table name
- [x] Custom field name
- [ ] Strict undefined check
- [ ] Implement changesets
- [ ] Polymorphism
- [ ] Validation
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-v3",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"description": "ZenStack",
"packageManager": "[email protected]",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack CLI",
"description": "FullStack database toolkit with built-in access control and automatic API generation.",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"type": "module",
"author": {
"name": "ZenStack Team"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-zenstack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-zenstack",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"description": "Create a new ZenStack project",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/language",
"description": "ZenStack ZModel language specification",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"license": "MIT",
"author": "ZenStack Team",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/runtime",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"description": "ZenStack Runtime",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/client/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { ToKyselySchema } from './query-builder';
type DialectConfig<Provider extends DataSourceProvider> =
Provider['type'] extends 'sqlite'
? Optional<SqliteDialectConfig, 'database'>
: Provider extends 'postgresql'
: Provider['type'] extends 'postgresql'
? Optional<PostgresDialectConfig, 'pool'>
: never;

Expand Down
7 changes: 7 additions & 0 deletions packages/runtime/test/client-api/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ describe.each(createClientSpecs(PG_DB_NAME))(
).toResolveTruthy();
});

it('ignores undefined filters', async () => {
await createUser();
await expect(
client.user.findMany({ where: { id: undefined } })
).toResolveWithLength(1);
});

// TODO: filter for bigint, decimal, bytes
}
);
1 change: 1 addition & 0 deletions packages/runtime/test/client-api/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe.each(createClientSpecs(PG_DB_NAME))(
r = await client.user.findMany();
expect(r).toHaveLength(1);
expect(r[0]?.createdAt).toBeInstanceOf(Date);

r = await client.user.findMany({ where: { id: user.id } });
expect(r).toHaveLength(1);

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/sdk",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"description": "ZenStack SDK",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/tanstack-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/tanstack-query",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"description": "",
"main": "index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/testtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/testtools",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"description": "ZenStack Test Tools",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/zod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/zod",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"description": "",
"type": "module",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion samples/blog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sample-todo",
"version": "3.0.0-alpha.2",
"version": "3.0.0-alpha.4",
"description": "",
"main": "index.js",
"scripts": {
Expand Down