|
| 1 | +--- |
| 2 | +title: "Clients and Dialects" |
| 3 | +description: "The LinkedQL clients and dialects" |
| 4 | +permalink: /entry/clients/ |
| 5 | +nav_order: 4 |
| 6 | +layout: page |
| 7 | +--- |
| 8 | + |
| 9 | +# Dialects & Clients |
| 10 | + |
| 11 | +LinkedQL ships with clients for each major SQL dialect. |
| 12 | + |
| 13 | +Each LinkedQL client extends its respective native connector and accepts the same initialization options. |
| 14 | +The PostgreSQL, MySQL, and MariaDB clients integrate directly with their native drivers, while **FlashQL** provides an in-memory SQL engine that speaks both dialects. |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## `1.1 |` PostgreSQL |
| 19 | + |
| 20 | +Use as a drop-in replacement for [`node-postgres`](https://www.npmjs.com/package/pg).<br> |
| 21 | +Speaks native **PostgreSQL**. |
| 22 | + |
| 23 | +```js |
| 24 | +import { PGClient } from '@linked-db/linked-ql/pg'; |
| 25 | + |
| 26 | +const client = new PGClient({ |
| 27 | + host: 'localhost', |
| 28 | + port: 5432, |
| 29 | + user: 'postgres', |
| 30 | + password: 'password', |
| 31 | + database: 'mydb', |
| 32 | + poolMode: false // defaults to pg.Client |
| 33 | +}); |
| 34 | +await client.connect(); |
| 35 | + |
| 36 | +const res = await client.query('SELECT 1::text AS result'); |
| 37 | +console.log(res.rows); // [{ result: '1' }] |
| 38 | + |
| 39 | +await client.disconnect(); |
| 40 | +``` |
| 41 | + |
| 42 | +### `1.1.1 |` Client Options |
| 43 | + |
| 44 | +`PGClient` accepts all options supported by `node-postgres`. |
| 45 | + |
| 46 | +Additional options: |
| 47 | + |
| 48 | +* **`poolMode`** (*Default*: `false`) — whether to connect over `pg.Pool` or `pg.Client`. |
| 49 | + |
| 50 | +### `1.1.2 |` Realtime Setup |
| 51 | + |
| 52 | +To enable **live queries**, ensure [logical replication](https://www.postgresql.org/docs/current/view-pg-replication-slots.html) is enabled on your database. |
| 53 | + |
| 54 | +Optionally specify the following to adapt LinkedQL to your setup: |
| 55 | + |
| 56 | +* **`walSlotName`** — (*Default*: `'linkedql_default_slot'`) replication slot name. |
| 57 | +* **`walSlotPersistence`** — slot lifecycle management:<br> |
| 58 | + `0` = ephemeral, DB-managed · `1` = ephemeral, LinkedQL-managed · `2` = persistent, external management implied. |
| 59 | +* **`pgPublications`** — (*Default*: `'linkedql_default_publication'`) publication name(s) to listen on. |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## `1.2 |` MySQL |
| 64 | + |
| 65 | +Use in place of [`mysql2`](https://www.npmjs.com/package/mysql2). |
| 66 | +Speaks native **MySQL**. |
| 67 | + |
| 68 | +```js |
| 69 | +import { MySQLClient } from '@linked-db/linked-ql/mysql'; |
| 70 | + |
| 71 | +const client = new MySQLClient({ |
| 72 | + host: 'localhost', |
| 73 | + port: 3306, |
| 74 | + user: 'root', |
| 75 | + password: 'password', |
| 76 | + database: 'mydb', |
| 77 | + poolMode: false // defaults to mysql.createConnection() |
| 78 | +}); |
| 79 | +await client.connect(); |
| 80 | + |
| 81 | +const res = await client.query('SELECT 1 AS `result`'); |
| 82 | +console.log(res.rows); // [{ result: 1 }] |
| 83 | + |
| 84 | +await client.disconnect(); |
| 85 | +``` |
| 86 | + |
| 87 | +### `1.2.1 |` Client Options |
| 88 | + |
| 89 | +`MySQLClient` accepts all connection options supported by `mysql2`. |
| 90 | + |
| 91 | +Additional options: |
| 92 | + |
| 93 | +* **`poolMode`** (*Default*: `false`) — whether to connect over `mysql.createPool()` or `mysql.createConnection()`. |
| 94 | + |
| 95 | +### `1.2.2 |` Realtime Setup |
| 96 | + |
| 97 | +Realtime capabilities for MySQL are **coming soon**. |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## `1.3 |` MariaDB |
| 102 | + |
| 103 | +Use in place of [`mariadb`](https://www.npmjs.com/package/mariadb`).<br> |
| 104 | +Speaks native **MariaDB / MySQL**. |
| 105 | + |
| 106 | +```js |
| 107 | +import { MariaDBClient } from '@linked-db/linked-ql/mariadb'; |
| 108 | + |
| 109 | +const client = new MariaDBClient({ |
| 110 | + host: 'localhost', |
| 111 | + port: 3306, |
| 112 | + user: 'root', |
| 113 | + password: 'password', |
| 114 | + database: 'mydb' |
| 115 | +}); |
| 116 | +await client.connect(); |
| 117 | + |
| 118 | +const res = await client.query('SELECT 1 AS `result`'); |
| 119 | +console.log(res.rows); // [{ result: 1 }] |
| 120 | + |
| 121 | +await client.disconnect(); |
| 122 | +``` |
| 123 | + |
| 124 | +### `1.3.1 |` Client Options |
| 125 | + |
| 126 | +`MariaDBClient` accepts all connection options supported by the native `mariadb` driver.<br> |
| 127 | +It always runs on a connection pool. |
| 128 | + |
| 129 | +### `1.3.2 |` Realtime Setup |
| 130 | + |
| 131 | +Realtime support for MariaDB is **coming soon**. |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## `1.4 |` FlashQL |
| 136 | + |
| 137 | +Use as an in-memory alternative to [`SQLite`](https://sqlite.org/) or [`PGLite`](https://pglite.dev/). |
| 138 | +Speaks both **PostgreSQL** and **MySQL** dialects. |
| 139 | + |
| 140 | +```js |
| 141 | +import { FlashClient } from '@linked-db/linked-ql/flash'; |
| 142 | + |
| 143 | +const client = new FlashClient(); |
| 144 | +await client.connect(); |
| 145 | + |
| 146 | +// PostgreSQL syntax (default dialect) |
| 147 | +const pgRes = await client.query('SELECT 1::text AS result'); |
| 148 | +console.log(pgRes.rows); // [{ result: '1' }] |
| 149 | + |
| 150 | +// MySQL syntax (explicit dialect) |
| 151 | +const myRes = await client.query('SELECT 1 AS `result`', { dialect: 'mysql' }); |
| 152 | +console.log(myRes.rows); // [{ result: 1 }] |
| 153 | + |
| 154 | +await client.disconnect(); |
| 155 | +``` |
| 156 | + |
| 157 | +### `1.4.1 |` Realtime Setup |
| 158 | + |
| 159 | +Realtime capabilities are built in. |
| 160 | +No configuration required — FlashQL automatically emits and processes change events internally. |
0 commit comments