-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
84 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/docs/docs/300-query-language.md → ...cs/200-query-language/000-introduction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Query language | ||
|
||
## Introduction | ||
Learn the basics of the SynthQL query language. [Read more](./query-language/introduction). | ||
|
||
## Examples | ||
Looking for examples? Checkout the [examples section](./query-language/examples). | ||
|
||
## Query composition | ||
SynthQL let's you build bigger queries from smaller ones. Learn about [query composition](./query-language/composition). | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
packages/docs/docs/200-security/index.md → ...ocs/docs/300-security/000-Introduction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Security | ||
|
||
## Introduction | ||
|
||
Learn the basics of security in SynthQL. [Read more](./security/introduction). | ||
|
||
## Query middleware | ||
|
||
Learn how to use query middlewares to add additional security checks to your queries. [Read more](./security/query-middleware). | ||
|
||
## Query permissions | ||
|
||
Learn how to add permissions to your queries, to implement ACL-like functionality. [Read more](./security/query-permissions). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
22 changes: 11 additions & 11 deletions
22
packages/docs/docs/500-lazy-queries.md → packages/docs/docs/500-deferred-queries.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
# Lazy queries | ||
# Deferred queries | ||
|
||
## The bigger the query, the longer the latency | ||
|
||
One of the disadvantages of large query trees is that they result in proportionally longer latencies. The reason is simple: you have to wait for the entire query tree to load before you can send the response back to the client. | ||
|
||
So the bigger the query, the longer the wait time. | ||
|
||
To mitigate this issue, SynthQL lets you mark parts of your query tree as `lazy`. A lazy boundary will split your query into two and will tell the QueryEngine to flush results to the client in sequences. | ||
To mitigate this issue, SynthQL lets you mark parts of your query tree with `.defer()`. A deferred boundary will split your query into two and will tell the QueryEngine to flush results to the client in sequences. | ||
|
||
This feature is similar to [GraphQL's @defer directive](https://graphql.org/blog/2020-12-08-improving-latency-with-defer-and-stream-directives/). | ||
|
||
## Example: Store with many products | ||
|
||
Let's imagine that you have a store that can sell hundreds of different products. You need to implement a Store page in which you display the store's properties and after ccrolling a bit the user can see a list of all the products sold by the store. | ||
Let's imagine that you have a store that can sell hundreds of different products. You need to implement a Store page in which you display the store's properties and after scrolling a bit the user can see a list of all the products sold by the store. | ||
|
||
To improve the latency of this page, you can mark the `products` query as `.lazy()` as follows: | ||
To improve the latency of this page, you can mark the `products` query as `.defer()` as follows: | ||
|
||
```tsx | ||
const products = from('products') | ||
.column('id', 'price', 'name') | ||
.lazy() // <======= this marks the products query as lazy | ||
.defer() // <======= this marks the products query as deferred | ||
.many(); | ||
|
||
const query = from('store').column('id', 'store_name', 'store_owner').include({ | ||
const query = from('store').column('store_name', 'store_owner').include({ | ||
products, | ||
}); | ||
|
||
useSynthql(query); | ||
``` | ||
|
||
Marking the `products` subquery as `lazy` will result in the query client first fetching the `store`, and then re-rendering the component when eventually the data from the `products` comes in. | ||
Marking the `products` subquery as `defer` will result in the query client first fetching the `store`, and then re-rendering the component when eventually the data from the `products` comes in. | ||
|
||
## What happens over the wire | ||
|
||
When the `QueryEngine` executes a query, it will flush results 'early' to the client, whenever it sees a `lazy()` boundary. In this example this will result in two lines of JSON being sent to the client over the same HTTP connection, as seen below: | ||
When the `QueryEngine` executes a query, it will flush results 'early' to the client, whenever it sees a `.defer()` boundary. In this example this will result in two lines of JSON being sent to the client over the same HTTP connection, as seen below: | ||
|
||
```ts | ||
```json | ||
// First line of JSON | ||
{id: '123', 'store_name': 'Fun Inc.', store_owner: 'Bob', products: {status:'pending'}} | ||
{"store_name": "Fun Inc.", "store_owner": "Bob", "products": {"status":"pending"}} | ||
|
||
// Once the products have loaded | ||
{id: '123', 'store_name': 'Toys Inc.', store_owner: 'Bill', products: {status:'done', data: [...]}} | ||
{"store_name": "Toys Inc.", "store_owner": "Bill", "products": {"status":"done", "data": [...]}} | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
# Generating types | ||
|
||
To generate a schema, create an instance of the `QueryEngine` and call the `generateSchema` function. | ||
SynthQL comes with a CLI tool for generating types from your database. These types are used to guarantee end to end type safety when building queries. | ||
|
||
```ts | ||
import { QueryEngine } from "@synthql/backend"; | ||
To generate types from your database, run the following command: | ||
|
||
```bash | ||
npx @synthql/cli generate \ | ||
|
||
# A list of schemas to include, separated by spaces | ||
--schemas public types \ | ||
|
||
const queryEngine = new QueryEngine({ ... }) | ||
# A list of tables to include, separated by spaces | ||
--tables table1 table2 \ | ||
|
||
await queryEngine.generateSchema({ | ||
schemas: ["public","another_schema"], | ||
out: "./src/generated/synthql/db.ts" | ||
}) | ||
# The connection string to your database | ||
# e.g. postgres://username:password@host:port/database | ||
--url DATABASE_URL \ | ||
|
||
# The default schema to use when no schema is specified in a query | ||
--defaultSchema luminovo | ||
``` | ||
|
||
Once the schema has been generated, you can import the `from` function to start building type-safe queries. | ||
You can also get help by running `npx @synthql/cli generate --help`. | ||
|
||
```ts | ||
import { from } from './src/generated/synthql/db.ts'; | ||
## synthql.config.json | ||
|
||
function findDog(id: string) { | ||
return from('dogs').where({ id }).one(); | ||
You can also generate types from a configuration file by running | ||
|
||
```bash | ||
npx @synthql/cli generate --configFile ./synthql.config.json --url DATABASE_URL | ||
``` | ||
|
||
Here's an example configuration file: | ||
|
||
```ts | ||
// at ./synthql.config.json | ||
{ | ||
"$schema": "https://synthql.dev/schemas/synthql.config.json", | ||
"schemas": ["public"], | ||
"tables": ["table1", "table2"], | ||
"defaultSchema": "luminovo" | ||
} | ||
``` |
10 changes: 5 additions & 5 deletions
10
...s/docs/docs/800-custom-query-executors.md → packages/docs/docs/800-custom-providers.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters