mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
add session api to use read replica
This commit is contained in:
19
deps/db-sync/src/logseq/db_sync/common.cljs
vendored
19
deps/db-sync/src/logseq/db_sync/common.cljs
vendored
@@ -67,12 +67,19 @@
|
|||||||
(.run stmt)))
|
(.run stmt)))
|
||||||
|
|
||||||
(defn <d1-all
|
(defn <d1-all
|
||||||
[^js db sql-str & args]
|
[^js db sql-or-opts & more]
|
||||||
(p/let [^js stmt (.prepare db sql-str)
|
(let [[opts sql-str args] (if (map? sql-or-opts)
|
||||||
^js stmt (if (seq args)
|
[sql-or-opts (first more) (rest more)]
|
||||||
(.apply (.-bind stmt) stmt (to-array args))
|
[nil sql-or-opts more])
|
||||||
stmt)]
|
session-mode (:session opts)
|
||||||
(.all stmt)))
|
session (if (some? session-mode)
|
||||||
|
(.withSession db session-mode)
|
||||||
|
(.withSession db))]
|
||||||
|
(p/let [^js stmt (.prepare session sql-str)
|
||||||
|
^js stmt (if (seq args)
|
||||||
|
(.apply (.-bind stmt) stmt (to-array args))
|
||||||
|
stmt)]
|
||||||
|
(.all stmt))))
|
||||||
|
|
||||||
(defn read-json [request]
|
(defn read-json [request]
|
||||||
(p/let [body (.text request)]
|
(p/let [body (.text request)]
|
||||||
|
|||||||
8
deps/db-sync/src/logseq/db_sync/index.cljs
vendored
8
deps/db-sync/src/logseq/db_sync/index.cljs
vendored
@@ -129,7 +129,7 @@
|
|||||||
|
|
||||||
(defn <user-id-by-email [db email]
|
(defn <user-id-by-email [db email]
|
||||||
(when (string? email)
|
(when (string? email)
|
||||||
(p/let [result (common/<d1-all db
|
(p/let [result (common/<d1-all db {:session "first-primary"}
|
||||||
"select id from users where email = ?"
|
"select id from users where email = ?"
|
||||||
email)
|
email)
|
||||||
rows (common/get-sql-rows result)
|
rows (common/get-sql-rows result)
|
||||||
@@ -157,7 +157,7 @@
|
|||||||
(defn <user-rsa-key-pair
|
(defn <user-rsa-key-pair
|
||||||
[db user-id]
|
[db user-id]
|
||||||
(when (string? user-id)
|
(when (string? user-id)
|
||||||
(p/let [result (common/<d1-all db
|
(p/let [result (common/<d1-all db {:session "first-primary"}
|
||||||
"select public_key, encrypted_private_key from user_rsa_keys where user_id = ?"
|
"select public_key, encrypted_private_key from user_rsa_keys where user_id = ?"
|
||||||
user-id)
|
user-id)
|
||||||
rows (common/get-sql-rows result)
|
rows (common/get-sql-rows result)
|
||||||
@@ -169,7 +169,7 @@
|
|||||||
(defn <user-rsa-public-key-by-email
|
(defn <user-rsa-public-key-by-email
|
||||||
[db email]
|
[db email]
|
||||||
(when (string? email)
|
(when (string? email)
|
||||||
(p/let [result (common/<d1-all db
|
(p/let [result (common/<d1-all db {:session "first-primary"}
|
||||||
(str "select k.public_key from user_rsa_keys k "
|
(str "select k.public_key from user_rsa_keys k "
|
||||||
"left join users u on k.user_id = u.id "
|
"left join users u on k.user_id = u.id "
|
||||||
"where u.email = ?")
|
"where u.email = ?")
|
||||||
@@ -222,7 +222,7 @@
|
|||||||
now)))
|
now)))
|
||||||
|
|
||||||
(defn <graph-members-list [db graph-id]
|
(defn <graph-members-list [db graph-id]
|
||||||
(p/let [result (common/<d1-all db
|
(p/let [result (common/<d1-all db {:session "first-primary"}
|
||||||
(str "select m.user_id, m.graph_id, m.role, m.invited_by, m.created_at, "
|
(str "select m.user_id, m.graph_id, m.role, m.invited_by, m.created_at, "
|
||||||
"u.email, u.username "
|
"u.email, u.username "
|
||||||
"from graph_members m "
|
"from graph_members m "
|
||||||
|
|||||||
Reference in New Issue
Block a user