-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (client): extract sync API and make DAL optional (#1355)
This PR extracts the sync method out of the DAL by introducing a `subscribe` method on the `ElectricClient.sync` object. To compute the shape requested by the user we need a description of the database schema, namely: - Table name, and for each table: - columns (column name + PG type) - outgoing and incoming relations The outgoing relations are the FKs in the table that reference a column in (another) table. The incoming relations are FKs defined in (another) table that reference a column of this table. The incoming relations are required in order to be able to traverse FKs in the reverse direction, e.g. this is needed when syncing the following shape because there is no FK from `issues` to `comments`, only from `comments` to `issues`: ```json { "table": "issues", "include": { "comments": true } } ``` The database description used to be generated by our generator and included in the generated Electric client. To truly extract the sync API i had to make it independent of the DAL and the generated client. Therefore, i extended the CLI to use the metadata that is provided with the migrations to generate the DB description and bundle that into the app. Note: - I modified our TS satellite client in the e2e tests such that every DAL query has raw equivalent and to dynamically dispatch to the right version depending whether we are running with or without the DAL. I introduced a matrix in CI such that every Satellite e2e test is ran once with the DAL and once without the DAL. Questions: - The modified CLI changes the behavior of `electric-sql generate` as by default it will no longer generate the DAL. If you want to generate the DAL, you need to run it with the `--with-dal` flag as in `electric-sql generate --with-dal`. Is thi acceptable, or we want to keep generating the DAL by default and have a `--no-dal` flag instead? - I modified the format of the table columns in the generated DB description, it was previously a `Map<TableName, PgType>` and is now represented as a `Record<TableName, PgType>`. While this is not strictly necessary, this simplifies the generation of the DB description. Downside is that clients generated with the old generator won't work with newer versions of the ts-client and will require re-generating the DAL with the new ts-client. Is this fine or should i change it back to using a `Map<TableName, PgType>` ?
- Loading branch information
Showing
40 changed files
with
2,454 additions
and
716 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"electric-sql": patch | ||
"@electric-sql/prisma-generator": patch | ||
--- | ||
|
||
Extract the sync API out of the DAL and make the DAL optional. |
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
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,3 @@ | ||
export { postgresConverter } from './postgres' | ||
export { sqliteConverter } from './sqlite' | ||
export { PgBasicType } from './types' |
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,3 @@ | ||
export type { TableName, AnyTable, AnyTableSchema } from './model' | ||
export { type DbSchema, createDbDescription } from './util/relations' | ||
export * from './conversions' |
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
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,7 +1,13 @@ | ||
export { ElectricClient } from './client' | ||
export type { ClientTables } from './client' | ||
export type { TableSchema } from './schema' | ||
export type { | ||
TableSchema, | ||
TableSchemas, | ||
TableName, | ||
AnyTableSchema, | ||
} from './schema' | ||
export { DbSchema, Relation } from './schema' | ||
export { Table } from './table' | ||
export type { AnyTable } from './table' | ||
export type { HKT } from '../util/hkt' | ||
export type { SyncStatus } from './shapes' |
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
Oops, something went wrong.