-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): PG on the client (#1215)
Preview: https://deploy-preview-128--electric-sql-website.netlify.app node-postgres driver docs may need editing if a change is made due to this: #1038 (comment)
- Loading branch information
Showing
23 changed files
with
219 additions
and
37 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
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
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
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
2 changes: 1 addition & 1 deletion
2
docs/integrations/drivers/server/node.md → ...grations/drivers/server/better-sqlite3.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,56 @@ | ||
--- | ||
title: PGlite | ||
--- | ||
|
||
ElectricSQL supports [Node.js](https://nodejs.org) server applications using [PGlite](https://github.com/electric-sql/pglite/), our lightweight WebAssembly build of Postgres. | ||
|
||
## Dependencies | ||
|
||
Add `@electric-sql/pglite` as a dependency to your app, e.g.: | ||
|
||
```shell | ||
npm install @electric-sql/pglite | ||
``` | ||
|
||
See the [PGlite repo](https://github.com/electric-sql/pglite/) for more information. | ||
|
||
## Usage | ||
|
||
```tsx | ||
// Import the PGlite database client. | ||
import { electrify } from 'electric-sql/pglite' | ||
|
||
// Import the adapter to electrify PGlite from the ElectricSQL library. | ||
import { PGlite } from '@electric-sql/pglite' | ||
|
||
// Import your generated database schema. | ||
import { schema } from './generated/client' | ||
|
||
// Define custom configuration if needed | ||
const config = { | ||
url: 'https://example.com:5133' | ||
} | ||
|
||
// Create the PGlite database connection. The first argument | ||
// is your Postgres `pgdata` directory. Changing this will | ||
// create/use a new local database. | ||
const conn = new PGlite('/path/to/postgres/datadir') | ||
|
||
// Instantiate your electric client. | ||
const electric = await electrify(conn, schema, config) | ||
|
||
// Connect to the sync service, passing along your authentication token | ||
// See Usage -> Authentication for more details. | ||
await electric.connect('your token') | ||
``` | ||
|
||
You can now use the client to read, write and sync data, e.g.: | ||
|
||
```tsx | ||
const { db } = electric | ||
|
||
const results = await db.projects.findMany() | ||
console.log(results) | ||
``` | ||
|
||
See <DocPageLink path="usage/data-access" /> and <DocPageLink path="integrations/frontend" /> for more information. |
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,56 @@ | ||
--- | ||
title: node-postgres | ||
--- | ||
|
||
ElectricSQL supports [Node.js](https://nodejs.org) server applications using the [node-postgres](https://node-postgres.com) driver. | ||
|
||
## Dependencies | ||
|
||
Add `pg` as a dependency to your app, e.g.: | ||
|
||
```shell | ||
npm install pg | ||
``` | ||
|
||
## Usage | ||
|
||
```tsx | ||
// Import the node-postgres database client. | ||
import pg from 'pg' | ||
|
||
// Import the adapter to electrify node-postgres from the ElectricSQL library. | ||
import { PGlite } from '@electric-sql/node-postgres' | ||
|
||
// Import your generated database schema. | ||
import { schema } from './generated/client' | ||
|
||
// Define custom configuration if needed | ||
const config = { | ||
url: 'https://example.com:5133' | ||
} | ||
|
||
// Create the node-postgres database connection. | ||
const conn = new pg.Client({ | ||
// Connection configuration, see: | ||
// https://node-postgres.com/apis/client | ||
}) | ||
await conn.connect() | ||
|
||
// Instantiate your electric client. | ||
const electric = await electrify(conn, schema, config) | ||
|
||
// Connect to the sync service, passing along your authentication token | ||
// See Usage -> Authentication for more details. | ||
await electric.connect('your token') | ||
``` | ||
|
||
You can now use the client to read, write and sync data, e.g.: | ||
|
||
```tsx | ||
const { db } = electric | ||
|
||
const results = await db.projects.findMany() | ||
console.log(results) | ||
``` | ||
|
||
See <DocPageLink path="usage/data-access" /> and <DocPageLink path="integrations/frontend" /> for more information. |
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,64 @@ | ||
--- | ||
title: PGlite | ||
--- | ||
|
||
ElectricSQL supports running in the web browser using [PGlite](https://github.com/electric-sql/pglite/), our lightweight WebAssembly build of Postgres that supports in-browser persistence using IndexedDB. | ||
|
||
## Dependencies | ||
|
||
Add `@electric-sql/pglite` as a dependency to your app, e.g.: | ||
|
||
```shell | ||
npm install @electric-sql/pglite | ||
``` | ||
|
||
See the [PGlite repo](https://github.com/electric-sql/pglite/) for more information. | ||
|
||
## Usage | ||
|
||
```tsx | ||
// Import the PGlite database client. | ||
import { electrify } from 'electric-sql/pglite' | ||
|
||
// Import the adapter to electrify PGlite from the ElectricSQL library. | ||
import { PGlite } from '@electric-sql/pglite' | ||
|
||
// Import your generated database schema. | ||
import { schema } from './generated/client' | ||
|
||
// Define custom configuration if needed | ||
const config = { | ||
url: 'https://example.com:5133' | ||
} | ||
|
||
// Create the PGlite database connection. The first argument | ||
// is your database name. Changing this will create/use a new | ||
// local database file. | ||
// PGlite uses a `idb://` prefix to specify that the database | ||
// is stored in indexedDB. | ||
const conn = new PGlite('idb://electric.db', { | ||
// You can optionally use the relaxed durability mode to | ||
// improve responsiveness. | ||
// This schedules flush to indexedDB for after a query has | ||
// returned. | ||
relaxedDurability: true, | ||
}) | ||
|
||
// Instantiate your electric client. | ||
const electric = await electrify(conn, schema, config) | ||
|
||
// Connect to the sync service, passing along your authentication token | ||
// See Usage -> Authentication for more details. | ||
await electric.connect('your token') | ||
``` | ||
|
||
You can now use the client to read, write and sync data, e.g.: | ||
|
||
```tsx | ||
const { db } = electric | ||
|
||
const results = await db.projects.findMany() | ||
console.log(results) | ||
``` | ||
|
||
See the [examples/web-wa-sqlite](https://github.com/electric-sql/electric/tree/main/examples/web-wa-sqlite) demo app, <DocPageLink path="usage/data-access" /> and <DocPageLink path="integrations/frontend" /> for more information. |
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
Oops, something went wrong.