8000 chore: remove schema files until their design is settled by colinhacks · Pull Request #6 · colinhacks/reylo · GitHub
[go: up one dir, main page]

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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ To install Reylo, you'll need:

- **TypeScript 7.1 (currently in beta).** The first release with content mappers.
- **Node 24 or later.**
- **A running dev database.** Postgres, MySQL 8.0.22 or later, or a SQLite file: Reylo reads your current schema from it. On Postgres and SQLite, [a schema file](https://reylo.dev/#schema-files) will do instead.
- **A running dev database.** Postgres, MySQL 8.0.22 or later, or a SQLite file: Reylo reads your current schema from it.

Install Reylo, the engine for your database and TypeScript 7.1:

Expand Down
49 changes: 6 additions & 43 deletions engine/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
//! A host finds the file (beside the project's `package.json`), reads it and hands the text over;
//! what the file names outside itself (the environment, `.env` files, the database) is the host's
//! to resolve, and a `${VAR}` in a URL stays as written. There is no dialect key: the URL's scheme
//! names the dialect, or, under `schema`, the one engine the project installed. A key the library
//! does not know is an error, so a typo does not pass for a default; the framework's `api` section
//! and `rest`, the section PorgREST would have read, are accepted as they are, and a top-level
//! `$schema` (the JSON Schema an editor validates the file against, which `reylo schema --config`
//! prints) is ignored. `cli` says which files `reylo generate` analyzes, and `schema` the SQL files
//! the importer types from in place of a database.
//! names the dialect. A key the library does not know is an error, so a typo does not pass for a
//! default; the framework's `api` section and `rest`, the section PorgREST would have read, are
//! accepted as they are, and a top-level `$schema` (the JSON Schema an editor validates the file
//! against, which `reylo schema --config` prints) is ignored. `cli` says which files `reylo
//! generate` analyzes.

use serde::{Deserialize, Serialize};

Expand All @@ -32,12 +31,6 @@ pub struct Project {
/// pooler can fail. The importer's alone: the framework serves through `url`.
#[serde(skip_serializing_if = "Option::is_none")]
pub direct_url: Option<String>,
/// The SQL files the importer's type check reads the schema from, in place of a database: a
/// path or a glob, or a list of them, relative to the project file (a `pg_dump --schema-only`,
/// SQLite's `.schema`, or a directory of migrations). The host loads them into a database of
/// its own (PGlite for Postgres, an in-memory SQLite) and never connects to `direct_url`.
#[serde(rename = "schema", default, deserialize_with = "one_or_many", skip_serializing_if = "Option::is_none")]
pub schema_files: Option<Vec<String>>,
/// The `.env` files the importer and Reylo Framework read, relative to the project file
/// (`.env.local`, then `.env`, when absent); the first that sets a variable wins, and the
/// process environment wins over all of them.
Expand Down Expand Up @@ -74,20 +67,6 @@ impl Cli {
}
}

/// A string, or a list of strings: `schema: schema.sql` and `schema: [a.sql, b.sql]` alike.
fn one_or_many<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Option<Vec<String>>, D::Error> {
#[derive(Deserialize)]
#[serde(untagged, expecting = "a path, or a list of paths")]
enum OneOrMany {
One(String),
Many(Vec<String>),
}
Ok(Some(match OneOrMany::deserialize(d)? {
OneOrMany::One(one) => vec![one],
OneOrMany::Many(many) => many,
}))
}

/// Why the file does not parse, at byte offsets in its text.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct ConfigError {
Expand Down Expand Up @@ -122,7 +101,7 @@ pub fn parse(text: &str) -> Result<Project, ConfigError> {
if masked != text {
project.url = project.url.as_deref().map(unmask_placeholders);
project.direct_url = project.direct_url.as_deref().map(unmask_placeholders);
for list in [&mut project.env, &mut project.schema_files, &mut project.cli.include, &mut project.cli.exclude].into_iter().flatten() {
for list in [&mut project.env, &mut project.cli.include, &mut project.cli.exclude].into_iter().flatten() {
for item in list.iter_mut() {
*item = unmask_placeholders(item);
}
Expand Down Expand Up @@ -213,22 +192,6 @@ mod tests {
assert_eq!(&text[e.start..e.end], "strict");
}

#[test]
fn schema_is_one_path_or_a_list() {
let p = parse("schema: db/schema.sql\n").unwrap();
assert_eq!(p.schema_files, Some(vec!["db/schema.sql".to_string()]));
assert_eq!(serde_json::to_value(&p).unwrap(), serde_json::json!({ "schema": ["db/schema.sql"] }));
let p = parse("schema: [schema.sql, \"migrations/*.up.sql\"]\n").unwrap();
assert_eq!(p.schema_files, Some(vec!["schema.sql".to_string(), "migrations/*.up.sql".to_string()]));
let p = parse("schema:\n - prisma/migrations/*/migration.sql\n").unwrap();
assert_eq!(p.schema_files, Some(vec!["prisma/migrations/*/migration.sql".to_string()]));
// Neither `$schema` nor a missing key is the importer's schema.
assert_eq!(parse("$schema: https://example.test/x.json\n").unwrap().schema_files, None);
let text = "schema: { file: schema.sql }\n";
let e = parse(text).unwrap_err();
assert!(e.message.contains("a path, or a list of paths"), "{}", e.message);
}

#[test]
fn a_framework_project_file_reads_with_its_schema_and_api_section() {
let text = "$schema: https://example.test/reylo.schema.json\nurl: ${DATABASE_URL}\nenv: [.env.local, .env]\napi:\n authenticators:\n clerk:\n jwt:\n jwks: ${JWKS_URL}\n codegen:\n typescript: { out: web/src/api }\n";
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"test": "node --test 'tests/**/*.test.ts'"
},
"devDependencies": {
"@electric-sql/pglite": "0.5.11",
"@reylosql/mysql": "link:packages/mysql",
"@reylosql/postgres": "link:packages/postgres",
"@reylosql/sqlite": "link:packages/sqlite",
Expand All @@ -56,7 +55,6 @@
"tinyglobby": "^0.2.17"
},
"peerDependencies": {
"@electric-sql/pglite": ">=0.5",
"@reylosql/mysql": "0.1.0",
"@reylosql/postgres": "0.1.0",
"@reylosql/sqlite": "0.1.0",
Expand All @@ -65,7 +63,6 @@
"postgres": ">=3"
},
"peerDependenciesMeta": {
"@electric-sql/pglite": { "optional": true },
"@reylosql/mysql": { "optional": true },
"@reylosql/postgres": { "optional": true },
"@reylosql/sqlite": { "optional": true },
Expand Down
Binary file modified packages/mysql/engine.wasm
Binary file not shown.
Binary file modified packages/postgres/engine.wasm
Binary file not shown.
Binary file modified packages/sqlite/engine.wasm
Binary file not shown.
13 changes: 0 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion site/content/docs/postgres.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This page is the reference behind [the main docs](/) for Postgres: the place to
| --- | --- |
| Versions | Postgres 18, 17 and 14 |
| URL | A `postgres://` or `postgresql://` URL, in `DATABASE_URL` or [`direct_url`](/#direct_url), a direct connection past a pooler such as PgBouncer |
| Type check | Reads the schema through postgres.js or `pg`, whichever your project has, or loads [your schema files](/#schema-files) into PGlite |
| Type check | Reads the schema through postgres.js or `pg`, whichever your project has |
| Drivers | postgres.js, `pg`, `pg-promise`, `Bun.sql`, PGlite, Neon and `@vercel/postgres` ([Drivers](#drivers)) |

<Details summary="View the schema behind the examples" id="schema">
Expand Down
2 changes: 1 addition & 1 deletion site/content/docs/sqlite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This page is the reference behind [the main docs](/) for SQLite: the place to lo
| --- | --- |
| Versions | The type check prepares each statement in Reylo's own SQLite 3.53, against the schema of your database file; your app runs on its driver's SQLite ([Functions](#functions)) |
| URL | A `file:` or `sqlite:` URL and a path, which starts at the directory of `package.json`, in `DATABASE_URL` or [`direct_url`](/#direct_url) |
| Type check | Reads the schema through Node's built-in `node:sqlite`, so it needs no driver, from your database file or [your schema files](/#schema-files) |
| Type check | Reads the schema through Node's built-in `node:sqlite`, so it needs no driver |
| Drivers | `better-sqlite3`, `node:sqlite`, `bun:sqlite`, libSQL, Turso's engine, Cloudflare D1, `sqlite3`, `sqlite` and `Bun.sql` ([Drivers](#drivers)) |

<Details summary="View the schema behind the examples" id="schema">
Expand Down
12 changes: 3 additions & 9 deletions site/content/sections/01-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Each setup has a complete, working example project to copy, whose README's "How
The example for that setup shows it end to end (node, nub, bun, vite, nextjs, esbuild, webpack, rspack, jest or cloudflare-workers): https://github.com/colinhacks/reylo/tree/main/examples/<name>
If the project runs on anything else, Reylo has no plugin for it yet: say so, and do not write one.
4. Set up the editor the project uses, or VS Code's settings when nothing in the project names an editor: https://reylo.dev/#editors
5. Point Reylo at the development database with DATABASE_URL, or with direct_url in .reylo.yaml; or, on Postgres or SQLite without one, at the schema's SQL files with schema in .reylo.yaml: https://reylo.dev/#database
5. Point Reylo at the development database with DATABASE_URL, or with direct_url in .reylo.yaml: https://reylo.dev/#database
6. Write a first query and run it with the project's own driver: https://reylo.dev/#usage and https://reylo.dev/#supported-drivers
For more queries, from nested JSON to bulk inserts, see https://reylo.dev/#inference and https://reylo.dev/#advanced
7. Run the typecheck script. The query's types come from the database, or the schema files; an error in a .sql file shows at its line and column.
7. Run the typecheck script. The query's types come from the database; an error in a .sql file shows at its line and column.
```

</AgentPrompt>
Expand Down Expand Up @@ -342,7 +342,7 @@ Zed doesn't send `.sql` files to the language server, so an error inside one sho

### Database

**Reylo reads your types from a live dev database.** It retrieves the types of each compiled query, its parameters and its columns, from the database itself. Reylo finds your dev database through the `DATABASE_URL` environment variable, and the URL's scheme tells it which database you use:
**Reylo requires a connection to a live dev database.** It retrieves the types of each compiled query, its parameters and its columns, from the database itself. Reylo finds your dev database through the `DATABASE_URL` environment variable, and the URL's scheme tells it which database you use:

```sh title=".env" tab="Postgres" tab-group="dialect"
# or postgresql://
Expand Down Expand Up @@ -378,9 +378,3 @@ Or specify a set of `.env` files to load:
env: [.env.development, .env]
```

To skip the database, point [`schema`](#schema-files) at your schema dump or migrations, on Postgres or SQLite:

```yaml title=".reylo.yaml"
schema: db/schema.sql
```

2 changes: 1 addition & 1 deletion site/content/sections/03-inference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Reylo reads the schema from the database file and [prepares](https://sqlite.org/

<Details summary="In CI, and in builds without a database" id="in-ci">

In CI, start the database, apply the migrations, and run `tsc --noEmit --runExternalCode` with `DATABASE_URL` set. Or set [`schema`](#schema-files), and the type check and every build step read your schema files instead, with no database. Your tests need the database too, or a filled `.reylo/`.
In CI, start the database, apply the migrations, and run `tsc --noEmit --runExternalCode` with `DATABASE_URL` set. Your tests need the database too, or a filled `.reylo/`.

Every step that loads a `.sql` file (the type check, a plugin, the preload) keeps its analysis in `.reylo/`, and a later step reads it from there:

Expand Down
31 changes: 0 additions & 31 deletions site/content/sections/04-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ direct_url: ${DATABASE_URL}
env: [.env.local, .env]
# an error for a parameter whose type cannot be inferred (the default)
strict_params: true
# SQL files to read your schema from instead of a database (none by default)
# schema: db/schema.sql
```

### `direct_url`
Expand Down Expand Up @@ -43,35 +41,6 @@ Point it at a direct connection, not a pooler: describing a query through a pool
direct_url: postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/app
```

### `schema` [#schema-files]

To type your queries with no database at all, as in CI, point `schema` at your schema's SQL files. Reylo loads them into a database of its own and never connects to `DATABASE_URL`:

```yaml title=".reylo.yaml"
schema: db/schema.sql
```

Dump the schema from your dev database. On Postgres, also install PGlite, which Reylo loads it into:

```sh tab="Postgres" tab-group="dialect"
pg_dump --schema-only "$DATABASE_URL" > db/schema.sql
npm install -D @electric-sql/pglite
```

```sh tab="SQLite" tab-group="dialect"
# loaded into an in-memory SQLite, so no package is needed
sqlite3 app.db .schema > db/schema.sql
```

Or list your migrations. Reylo applies them in the order your migration tool does, and skips down migrations:

```yaml title=".reylo.yaml"
# on Prisma, prisma/migrations/*/migration.sql
schema: migrations/*.sql
```

MySQL types come from its server, so `schema` works on Postgres and SQLite only. PGlite is Postgres 18 with its contrib extensions: a schema that needs another, such as PostGIS, needs a database at `direct_url`.

### `env`

The `.env` files Reylo reads, relative to `.reylo.yaml`. The first file that sets a variable wins, and the environment 5711 wins over every file.
Expand Down
Loading
Loading
0