You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -919,7 +923,7 @@ For more on the runtime setup side, see [Dialects & Clients ↗](https://linked-
919
923
920
924
#### The Edge Protocol does the heavy lifting
921
925
922
-
As against just sending raw SQL over HTTP, the client (`EdgeClient`) sends structured operations that map directly to the LinkedQL client interface (e.g. `query()`, `stream()`, `subscribe()`, etc.).
926
+
As against just sending raw SQL over HTTP or message port, the client (`EdgeClient`) sends structured operations that map directly to the upstream LinkedQL client interface (e.g. `query()`, `stream()`, `subscribe()`, etc.).
923
927
924
928
This preserves:
925
929
@@ -933,10 +937,10 @@ This preserves:
933
937
934
938
In this scenario, we demonstrate a hybrid data architecture where the goal is to:
935
939
936
-
> Query remote data **as if it were local**, while controlling
940
+
> Query upstream data **as if it were local**, while controlling
937
941
> what stays remote, what gets cached locally, and what stays in sync.
938
942
939
-
The idea is straight-forward in FlashQL: you simply create a view (a database view) in your local database that mirrors the remote database.
943
+
The idea is straight-forward in FlashQL: you simply create a view (a database view) in your local database that points to the upstream database as its origin.
940
944
941
945
```js
942
946
await db.query(`
@@ -946,11 +950,28 @@ await db.query(`
946
950
`);
947
951
```
948
952
949
-
Notice the `WITH (replication_origin = ...)` specifier. That's the magic.
953
+
Notice the `WITH (replication_origin = ...)` specifier. That's the part that turns a regular view into a foreign view.
954
+
955
+
Now, querying `public.users` on the local database will query `public.users` on the upstream database:
950
956
951
-
Rows inthisview (`public.users`) will mirror `public.users`in the upstream database.
957
+
```js
958
+
await db.query(`
959
+
SELECT*FROMpublic.users;
960
+
`);
961
+
```
952
962
953
-
But just one more thing is required forthis to work:
963
+
Being a regular table, it can be used just like one – e.g. in joins:
964
+
965
+
```js
966
+
await db.query(`
967
+
SELECT*FROMpublic.posts
968
+
LEFTJOINpublic.usersONposts.user_id=users.id;
969
+
`);
970
+
```
971
+
972
+
The query executes as one relational graph – but composed of both local and remote data.
973
+
974
+
But forthis work, one thing is required:
954
975
955
976
> a way to connect the local FlashQL instance to the upstream database.
956
977
@@ -962,7 +983,7 @@ import { EdgeClient } from '@linked-db/linked-ql/edge';
962
983
963
984
const db = new FlashQL({
964
985
// The hook to remote
965
-
async onCreateForeignClient(originUrl) {
986
+
async getUpstreamClient(originUrl) {
966
987
return new EdgeClient({ url: originUrl, type: 'http' });
967
988
}
968
989
});
@@ -972,46 +993,27 @@ await db.connect();
972
993
973
994
This is now a local FlashQL instance that can talk to an upstream database ondemand.
974
995
975
-
Above, the `onCreateForeignClient()` hook will recieve `'/api/db'` – the value of the `replication_origin` config.
976
-
977
-
Now, querying `public.users` on the local database will query `public.users` on the upstream database:
978
-
979
-
```js
980
-
await db.query(`
981
-
SELECT*FROMpublic.users;
982
-
`);
983
-
```
996
+
Above, the `getUpstreamClient()` factory will recieve `'/api/db'` – the value of the `replication_origin` config.
984
997
985
-
Being a regular table, it can be used just like one – e.g. in joins:
986
-
987
-
```js
988
-
await db.query(`
989
-
SELECT*FROMpublic.posts
990
-
LEFTJOINpublic.usersONposts.user_id=users.id;
991
-
`);
992
-
```
993
-
994
-
The query executes as one relational graph – but composed of both local and remote data.
995
-
996
-
Given this as the base, FlashQL further lets you create other types of views with different replication modes.
998
+
Given this as the base, FlashQL further lets you create different types of views for different replication behaviours.
997
999
998
1000
These modes determine how mirroring works; i.e. whether data stays remote, or is cached locally, or stays in sync.
0 commit comments