mirror of
https://tangled.org/tranquil.farm/tranquil-pds
synced 2026-09-08 03:06:54 +00:00
SQLx raw text queries to yummy query macro
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
/target
|
||||
.sqlx
|
||||
|
||||
.env
|
||||
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT u.handle, u.did, u.email, k.key_bytes\n FROM sessions s\n JOIN users u ON s.did = u.did\n JOIN user_keys k ON u.id = k.user_id\n WHERE s.access_jwt = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "handle",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "email",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "09d75b756a6bd981cf2a9e922eccc38677bee474813c66465904aec3c0da1c3e"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO blobs (cid, mime_type, size_bytes, created_by_user, storage_key) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (cid) DO NOTHING",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Int8",
|
||||
"Uuid",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "0f10bde03edc0233a332e210a84a4186977c71efd3be80e2508a60ea5802cb1b"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT u.did, r.repo_root_cid\n FROM repos r\n JOIN users u ON r.user_id = u.id\n WHERE u.did > $1\n ORDER BY u.did ASC\n LIMIT $2\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "repo_root_cid",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "0f8fd9cbb1ff0fd8951ce082a82cc058ec6db0dde3ab0059d6f340a1fd9ddade"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT cid FROM blobs\n WHERE created_by_user = $1 AND cid > $2 AND created_at > $3\n ORDER BY cid ASC\n LIMIT $4\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "cid",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Text",
|
||||
"Timestamptz",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "0fdf13907693d130babae38f4bb1df772dc11ab682f47918cacb5ae186b4eb24"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO repos (user_id, repo_root_cid) VALUES ($1, $2)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "14a68a119586aa980fb7b64646c1373eecd788e508246b5ad84e31b1adbdd2c1"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO app_passwords (user_id, name, password_hash, created_at, privileged) VALUES ($1, $2, $3, $4, $5)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Text",
|
||||
"Text",
|
||||
"Timestamptz",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "15a3cb31c36192c76c0cfa881043d70a1cc2c212fa382f8d9efc3c35ea4e66c1"
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT did, handle, email, created_at\n FROM users\n WHERE did = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "handle",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "email",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "176d30f31356a4d128764c9c2eece81f8079a29e40b07ba58adc4380d58068c8"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT u.did, r.repo_root_cid\n FROM users u\n LEFT JOIN repos r ON u.id = r.user_id\n WHERE u.did = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "repo_root_cid",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "1d3748694f23a407e26c793cc43e91c4fa9753dc7c7fd964f6c43de27c5bac4a"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE invite_codes SET available_uses = available_uses - 1 WHERE code = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "1ee6eda3e44660e7f14fcfe56adc2d41c72901b9c701fc7b992314e5370b32dc"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO invite_code_uses (code, used_by_user) VALUES ($1, $2)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "222699c46b99152404863463b8bdffb9452112e3d50ec352c96c1398d3e21504"
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT u.id, u.did, u.handle, u.password_hash, k.key_bytes FROM users u JOIN user_keys k ON u.id = k.user_id WHERE u.handle = $1 OR u.email = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "handle",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "password_hash",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "2305db96343fcb721adc4a6a608b64678f707928d3f9395070f5e21a5ca9b601"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE users SET deactivated_at = NULL WHERE did = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "23201d4e26bc650939e30f69fb0bca00d351d057098afebc1017f70a84b4bd22"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT 1 as one FROM blobs WHERE cid = $1 AND created_by_user = $2",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "one",
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "423bbfd2ddf9b41d3bb339b8b94ac47524dc9233ec70cf2b6c5e9bc2de49b22d"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT s.did, k.key_bytes, u.handle\n FROM sessions s\n JOIN users u ON s.did = u.did\n JOIN user_keys k ON u.id = k.user_id\n WHERE s.access_jwt = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "handle",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "47c914ca6080c5cedf0c3f6ca7cd4cd49e8fb691b34d19511b7a1ab8b3606cdf"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE users SET email = $1 WHERE did = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "48915485884524f68783351bd61e9790dd7e729e5776adc66b9d0114bb8cd73a"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT s.did, k.key_bytes\n FROM sessions s\n JOIN users u ON s.did = u.did\n JOIN user_keys k ON u.id = k.user_id\n WHERE s.access_jwt = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "48ae289ec37b367a6ec3d74895acaf8c3dc93e65d243434b6947ead95ca8c416"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM users WHERE id = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "50293c2e54af11d4c2a553e29b671cef087a159c6ee7182d8ca929ecb748f3b7"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM sessions WHERE access_jwt = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "52437f0d7f91d29d7438263a1f658a838601038d911be8781b91ebeec8a54b89"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE users SET handle = $1 WHERE id = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "572b136b4196b7d755a252bc5bbf14b3765fc2e606b9512493e90efb4f1305fb"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE users SET password_hash = $1 WHERE did = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "59e975c8599091b527ea2d097c68a8288360962d3e67f4db22e3dd92be924932"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT r.repo_root_cid\n FROM repos r\n JOIN users u ON r.user_id = u.id\n WHERE u.did = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "repo_root_cid",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "5b692e8f6d32dcbdcb45a3fff152a2be5672aadd807a4abab6914f80d57cba02"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO users (handle, email, did, password_hash) VALUES ($1, $2, $3, $4) RETURNING id",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Text",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "6c3a6dbf8d0d2a460054f093bd2ec1130ea91911d7d187cafcb4573be12bfcf4"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT id FROM users WHERE handle = $1 AND id != $2",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "6fd476d5640c20dc67db8e61e16b2f805e947ec404021cf93f6699f87bd7cfa5"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT repo_root_cid FROM repos WHERE user_id = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "repo_root_cid",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "77dfbc702362db9bb87c9d17c4d985287d8faa024981ae26c995dfc53fb486fd"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM user_keys WHERE user_id = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "7d0e11989d1b3f9c74daa3009505161369600509f103244fcd485b88869ee365"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT did FROM users WHERE handle = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "7d65d4608e93daa645ca0f8f6c7a23fb1bdaf50c7b0de900b1777542baf79d74"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM repos WHERE user_id = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "824293a46fd22d2c6bf7dde85156214d561a95125ee3ba0f3bd6bb2c3a7625e5"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT id FROM users WHERE did = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "8e69c8aebcb15c6956b8a0b9324dcc8668b2e14731945ceaf30b756050be9882"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM blobs WHERE created_by_user = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "997cff04226e18bf4d5025092d0daf0450292bcbdba21b8530706797144dcafa"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM sessions WHERE did = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "9c42b607a971b3a102d247def6c6fd322013f3885e9d0232d6e846220f893c49"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE sessions SET access_jwt = $1, refresh_jwt = $2 WHERE refresh_jwt = $3",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "a5b7ceaa177ef136a0e2421eaca3f3edf283e9305bd4675d72a1b7a02c3dfc83"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE users SET deactivated_at = NOW() WHERE did = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "a802bf661ef9a9baa41604b31e3cca9067ca467faef9c952e98db418157c0642"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE users SET handle = $1 WHERE did = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "aac3acbfc4f27b98054602de28b763ce15e3a70a9e6741114d12f2d173f631fe"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT id, did FROM users WHERE handle = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "b2c53e6a278c4549c99a5b98cc7ca77fc1e9cd39a591c1d8ec1ca41adfffa3a6"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT storage_key, mime_type FROM blobs WHERE cid = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "storage_key",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "mime_type",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "bb243abd63d10a43b11fa4f93644149f315894496255c5538f131b2c7aeb763b"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT deactivated_at FROM users WHERE did = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "deactivated_at",
|
||||
"type_info": "Timestamptz"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "bf2b237ee5cfe66d038dce3f564c05a683d391aebda7871d65d302e04b5d733f"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT cid FROM blobs\n WHERE created_by_user = $1 AND cid > $2\n ORDER BY cid ASC\n LIMIT $3\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "cid",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Text",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "bf55c87dfdeb7bc18663a50d10eeee0e53fade51c1c47bed9580072435baefea"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT record_cid FROM records WHERE repo_id = $1 AND collection = 'app.bsky.graph.follow'",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "record_cid",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "bf60faafb5c79a149ba237a984f78d068b5d691f6762641412a5aa1517605c04"
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT did, handle, email, created_at\n FROM users\n WHERE did = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "handle",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "email",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "c2a90157c47bf1c36f08f4608932d214cc26b4794e0b922b1dae3dad18a7ddc0"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO user_keys (user_id, key_bytes) VALUES ($1, $2)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Bytea"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "c4c9842e69c5fd4f4a2ebc176078af2a5f98beb3ea4d3c6af5b1b8fed2ec50e3"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.refresh_jwt = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "c949b23cf6d795c58e4c35907628bbb85714e9c49a569653b17acab60e1674ac"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT key_bytes FROM user_keys WHERE user_id = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "ce27e2da1f15cad97d2e31fda964e1d7017154fa559a8d9851728fb23af871cd"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT name, created_at, privileged FROM app_passwords WHERE user_id = $1 ORDER BY created_at DESC",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "name",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "created_at",
|
||||
"type_info": "Timestamptz"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "privileged",
|
||||
"type_info": "Bool"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "cec87a805457bcac6db8be601861b351a9332c649433894547176f6e4d672d01"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT s.did, k.key_bytes, u.id as user_id\n FROM sessions s\n JOIN users u ON s.did = u.did\n JOIN user_keys k ON u.id = k.user_id\n WHERE s.access_jwt = $1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "user_id",
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "d31423ddcb625250d7c15581e8c9242ec6290b41507eb710744ad900d482222d"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO sessions (access_jwt, refresh_jwt, did) VALUES ($1, $2, $3)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "db9950690548510474a2bf755b4c4c103b284e82e3cf23d17fc99cd2fc728c64"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT available_uses FROM invite_codes WHERE code = $1 FOR UPDATE",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "available_uses",
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "e2746221a24351293447246af539b5a847129cf93233dd98161193d4b7156b45"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT id FROM users WHERE handle = $1 AND did != $2",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "e80274b0731ed0ff9a1a1ae444eefadc193a172795b41c71445717020e6367d6"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT handle FROM users WHERE did = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "handle",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "ec5e14110d69ba47e8dd4447569c31506220df7759d0449e20d224609c7e6c4c"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT 1 as one FROM users WHERE handle = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "one",
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "ed34111a7f41b419a23d16ddd23cbc6aff9ab373946ff243512c52f857b7980d"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT id FROM app_passwords WHERE user_id = $1 AND name = $2",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "id",
|
||||
"type_info": "Uuid"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "eecc3bc506aafe17d7804b9749dc00bd9fedcb148d2a339bbf7ffba08541e8f6"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM records WHERE repo_id = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "eed03ee02de1828a665bc268ba135511005416b122bccb79374204a8023ace41"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT k.key_bytes FROM user_keys k JOIN users u ON k.user_id = u.id WHERE u.did = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "ef55a06bcea9b1a0d744df4fe353260ae4d6d93bbf5ea73133db65e38f6241ee"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "DELETE FROM app_passwords WHERE user_id = $1 AND name = $2",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "f1d4742aaa1d48f4a944d50743a51b0938cec852d0238347883dc110050e8d3a"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT password_hash FROM app_passwords WHERE user_id = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "password_hash",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "f8bee08776a6e246bdee70c0452217e8b654bf8617524edb4add139582b966ac"
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.access_jwt = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "did",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "key_bytes",
|
||||
"type_info": "Bytea"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "f91a07e40484ade5b4c72addf62e4ad82feab312645c0b7a4ea69c0e55e17b14"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT COUNT(*) FROM records WHERE repo_id = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "count",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "fa09feeb85d8648a8ebf339a69114ab6b3c6336642d6907ed4549b601e401f82"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO reports (id, reason_type, reason, subject_json, reported_by_did, created_at) VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Text",
|
||||
"Text",
|
||||
"Jsonb",
|
||||
"Text",
|
||||
"Timestamptz"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "fc06fa0ba9ae769e68c7386a9236995fe678a15e63a692b8460d692b242ea3c7"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT COUNT(*) FROM blobs WHERE created_by_user = $1",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "count",
|
||||
"type_info": "Int8"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
null
|
||||
]
|
||||
},
|
||||
"hash": "fd42681b7af9c795643baf65a998a55822ea81a07b651385740401f62bf8a8ae"
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT collection, rkey, record_cid FROM records WHERE repo_id = $1 AND (collection, rkey) > ($2, $3) ORDER BY collection, rkey LIMIT $4",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "collection",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "rkey",
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "record_cid",
|
||||
"type_info": "Text"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Uuid",
|
||||
"Text",
|
||||
"Text",
|
||||
"Int8"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "ff7899984ea138f1e608fa862def47402369a428ac9116c653890e5fcaa0015b"
|
||||
}
|
||||
+25
-51
@@ -7,7 +7,6 @@ use axum::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::Row;
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -57,31 +56,26 @@ pub async fn get_account_info(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query(
|
||||
let result = sqlx::query!(
|
||||
r#"
|
||||
SELECT did, handle, email, created_at
|
||||
FROM users
|
||||
WHERE did = $1
|
||||
"#,
|
||||
did
|
||||
)
|
||||
.bind(did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(Some(row)) => {
|
||||
let user_did: String = row.get("did");
|
||||
let handle: String = row.get("handle");
|
||||
let email: String = row.get("email");
|
||||
let created_at: chrono::DateTime<chrono::Utc> = row.get("created_at");
|
||||
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(AccountInfo {
|
||||
did: user_did,
|
||||
handle,
|
||||
email: Some(email),
|
||||
indexed_at: created_at.to_rfc3339(),
|
||||
did: row.did,
|
||||
handle: row.handle,
|
||||
email: Some(row.email),
|
||||
indexed_at: row.created_at.to_rfc3339(),
|
||||
invite_note: None,
|
||||
invites_disabled: false,
|
||||
email_confirmed_at: None,
|
||||
@@ -141,28 +135,23 @@ pub async fn get_account_infos(
|
||||
continue;
|
||||
}
|
||||
|
||||
let result = sqlx::query(
|
||||
let result = sqlx::query!(
|
||||
r#"
|
||||
SELECT did, handle, email, created_at
|
||||
FROM users
|
||||
WHERE did = $1
|
||||
"#,
|
||||
did
|
||||
)
|
||||
.bind(did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
if let Ok(Some(row)) = result {
|
||||
let user_did: String = row.get("did");
|
||||
let handle: String = row.get("handle");
|
||||
let email: String = row.get("email");
|
||||
let created_at: chrono::DateTime<chrono::Utc> = row.get("created_at");
|
||||
|
||||
infos.push(AccountInfo {
|
||||
did: user_did,
|
||||
handle,
|
||||
email: Some(email),
|
||||
indexed_at: created_at.to_rfc3339(),
|
||||
did: row.did,
|
||||
handle: row.handle,
|
||||
email: Some(row.email),
|
||||
indexed_at: row.created_at.to_rfc3339(),
|
||||
invite_note: None,
|
||||
invites_disabled: false,
|
||||
email_confirmed_at: None,
|
||||
@@ -202,13 +191,12 @@ pub async fn delete_account(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let user = sqlx::query("SELECT id FROM users WHERE did = $1")
|
||||
.bind(did)
|
||||
let user = sqlx::query!("SELECT id FROM users WHERE did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let user_id: uuid::Uuid = match user {
|
||||
Ok(Some(row)) => row.get("id"),
|
||||
let user_id = match user {
|
||||
Ok(Some(row)) => row.id,
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::NOT_FOUND,
|
||||
@@ -226,33 +214,27 @@ pub async fn delete_account(
|
||||
}
|
||||
};
|
||||
|
||||
let _ = sqlx::query("DELETE FROM sessions WHERE did = $1")
|
||||
.bind(did)
|
||||
let _ = sqlx::query!("DELETE FROM sessions WHERE did = $1", did)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
let _ = sqlx::query("DELETE FROM records WHERE repo_id = $1")
|
||||
.bind(user_id)
|
||||
let _ = sqlx::query!("DELETE FROM records WHERE repo_id = $1", user_id)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
let _ = sqlx::query("DELETE FROM repos WHERE user_id = $1")
|
||||
.bind(user_id)
|
||||
let _ = sqlx::query!("DELETE FROM repos WHERE user_id = $1", user_id)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
let _ = sqlx::query("DELETE FROM blobs WHERE created_by_user = $1")
|
||||
.bind(user_id)
|
||||
let _ = sqlx::query!("DELETE FROM blobs WHERE created_by_user = $1", user_id)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
let _ = sqlx::query("DELETE FROM user_keys WHERE user_id = $1")
|
||||
.bind(user_id)
|
||||
let _ = sqlx::query!("DELETE FROM user_keys WHERE user_id = $1", user_id)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
let result = sqlx::query("DELETE FROM users WHERE id = $1")
|
||||
.bind(user_id)
|
||||
let result = sqlx::query!("DELETE FROM users WHERE id = $1", user_id)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -300,9 +282,7 @@ pub async fn update_account_email(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query("UPDATE users SET email = $1 WHERE did = $2")
|
||||
.bind(email)
|
||||
.bind(account)
|
||||
let result = sqlx::query!("UPDATE users SET email = $1 WHERE did = $2", email, account)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -370,9 +350,7 @@ pub async fn update_account_handle(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let existing = sqlx::query("SELECT id FROM users WHERE handle = $1 AND did != $2")
|
||||
.bind(handle)
|
||||
.bind(did)
|
||||
let existing = sqlx::query!("SELECT id FROM users WHERE handle = $1 AND did != $2", handle, did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -384,9 +362,7 @@ pub async fn update_account_handle(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query("UPDATE users SET handle = $1 WHERE did = $2")
|
||||
.bind(handle)
|
||||
.bind(did)
|
||||
let result = sqlx::query!("UPDATE users SET handle = $1 WHERE did = $2", handle, did)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -455,9 +431,7 @@ pub async fn update_account_password(
|
||||
}
|
||||
};
|
||||
|
||||
let result = sqlx::query("UPDATE users SET password_hash = $1 WHERE did = $2")
|
||||
.bind(&password_hash)
|
||||
.bind(did)
|
||||
let result = sqlx::query!("UPDATE users SET password_hash = $1 WHERE did = $2", password_hash, did)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
|
||||
+11
-15
@@ -59,19 +59,16 @@ pub async fn get_timeline(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
"SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.access_jwt = $1"
|
||||
let session = sqlx::query!(
|
||||
"SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.access_jwt = $1",
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await
|
||||
.unwrap_or(None);
|
||||
|
||||
let (did, key_bytes) = match session {
|
||||
Some(row) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
),
|
||||
Some(row) => (row.did, row.key_bytes),
|
||||
None => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -89,13 +86,12 @@ pub async fn get_timeline(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let user_query = sqlx::query("SELECT id FROM users WHERE did = $1")
|
||||
.bind(&did)
|
||||
let user_query = sqlx::query!("SELECT id FROM users WHERE did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let user_id: uuid::Uuid = match user_query {
|
||||
Ok(Some(row)) => row.get("id"),
|
||||
let user_id = match user_query {
|
||||
Ok(Some(row)) => row.id,
|
||||
_ => {
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
@@ -105,15 +101,15 @@ pub async fn get_timeline(
|
||||
}
|
||||
};
|
||||
|
||||
let follows_query = sqlx::query(
|
||||
"SELECT record_cid FROM records WHERE repo_id = $1 AND collection = 'app.bsky.graph.follow'"
|
||||
let follows_query = sqlx::query!(
|
||||
"SELECT record_cid FROM records WHERE repo_id = $1 AND collection = 'app.bsky.graph.follow'",
|
||||
user_id
|
||||
)
|
||||
.bind(user_id)
|
||||
.fetch_all(&state.db)
|
||||
.await;
|
||||
|
||||
let follow_cids: Vec<String> = match follows_query {
|
||||
Ok(rows) => rows.iter().map(|r| r.get("record_cid")).collect(),
|
||||
Ok(rows) => rows.iter().map(|r| r.record_cid.clone()).collect(),
|
||||
Err(e) => {
|
||||
error!("Failed to get follows: {:?}", e);
|
||||
return (
|
||||
|
||||
+19
-29
@@ -13,7 +13,6 @@ use k256::SecretKey;
|
||||
use rand::rngs::OsRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::Row;
|
||||
use std::sync::Arc;
|
||||
use tracing::{error, info};
|
||||
|
||||
@@ -82,8 +81,7 @@ pub async fn create_account(
|
||||
}
|
||||
};
|
||||
|
||||
let exists_query = sqlx::query("SELECT 1 FROM users WHERE handle = $1")
|
||||
.bind(&input.handle)
|
||||
let exists_query = sqlx::query!("SELECT 1 as one FROM users WHERE handle = $1", input.handle)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await;
|
||||
|
||||
@@ -108,22 +106,20 @@ pub async fn create_account(
|
||||
|
||||
if let Some(code) = &input.invite_code {
|
||||
let invite_query =
|
||||
sqlx::query("SELECT available_uses FROM invite_codes WHERE code = $1 FOR UPDATE")
|
||||
.bind(code)
|
||||
sqlx::query!("SELECT available_uses FROM invite_codes WHERE code = $1 FOR UPDATE", code)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await;
|
||||
|
||||
match invite_query {
|
||||
Ok(Some(row)) => {
|
||||
let uses: i32 = row.get("available_uses");
|
||||
if uses <= 0 {
|
||||
if row.available_uses <= 0 {
|
||||
return (StatusCode::BAD_REQUEST, Json(json!({"error": "InvalidInviteCode", "message": "Invite code exhausted"}))).into_response();
|
||||
}
|
||||
|
||||
let update_invite = sqlx::query(
|
||||
let update_invite = sqlx::query!(
|
||||
"UPDATE invite_codes SET available_uses = available_uses - 1 WHERE code = $1",
|
||||
code
|
||||
)
|
||||
.bind(code)
|
||||
.execute(&mut *tx)
|
||||
.await;
|
||||
|
||||
@@ -166,16 +162,18 @@ pub async fn create_account(
|
||||
}
|
||||
};
|
||||
|
||||
let user_insert = sqlx::query("INSERT INTO users (handle, email, did, password_hash) VALUES ($1, $2, $3, $4) RETURNING id")
|
||||
.bind(&input.handle)
|
||||
.bind(&input.email)
|
||||
.bind(&did)
|
||||
.bind(&password_hash)
|
||||
let user_insert = sqlx::query!(
|
||||
"INSERT INTO users (handle, email, did, password_hash) VALUES ($1, $2, $3, $4) RETURNING id",
|
||||
input.handle,
|
||||
input.email,
|
||||
did,
|
||||
password_hash
|
||||
)
|
||||
.fetch_one(&mut *tx)
|
||||
.await;
|
||||
|
||||
let user_id: uuid::Uuid = match user_insert {
|
||||
Ok(row) => row.get("id"),
|
||||
let user_id = match user_insert {
|
||||
Ok(row) => row.id,
|
||||
Err(e) => {
|
||||
error!("Error inserting user: {:?}", e);
|
||||
// TODO: Check for unique constraint violation on email/did specifically
|
||||
@@ -190,9 +188,7 @@ pub async fn create_account(
|
||||
let secret_key = SecretKey::random(&mut OsRng);
|
||||
let secret_key_bytes = secret_key.to_bytes();
|
||||
|
||||
let key_insert = sqlx::query("INSERT INTO user_keys (user_id, key_bytes) VALUES ($1, $2)")
|
||||
.bind(user_id)
|
||||
.bind(&secret_key_bytes[..])
|
||||
let key_insert = sqlx::query!("INSERT INTO user_keys (user_id, key_bytes) VALUES ($1, $2)", user_id, &secret_key_bytes[..])
|
||||
.execute(&mut *tx)
|
||||
.await;
|
||||
|
||||
@@ -257,9 +253,8 @@ pub async fn create_account(
|
||||
}
|
||||
};
|
||||
|
||||
let repo_insert = sqlx::query("INSERT INTO repos (user_id, repo_root_cid) VALUES ($1, $2)")
|
||||
.bind(user_id)
|
||||
.bind(commit_cid.to_string())
|
||||
let commit_cid_str = commit_cid.to_string();
|
||||
let repo_insert = sqlx::query!("INSERT INTO repos (user_id, repo_root_cid) VALUES ($1, $2)", user_id, commit_cid_str)
|
||||
.execute(&mut *tx)
|
||||
.await;
|
||||
|
||||
@@ -274,9 +269,7 @@ pub async fn create_account(
|
||||
|
||||
if let Some(code) = &input.invite_code {
|
||||
let use_insert =
|
||||
sqlx::query("INSERT INTO invite_code_uses (code, used_by_user) VALUES ($1, $2)")
|
||||
.bind(code)
|
||||
.bind(user_id)
|
||||
sqlx::query!("INSERT INTO invite_code_uses (code, used_by_user) VALUES ($1, $2)", code, user_id)
|
||||
.execute(&mut *tx)
|
||||
.await;
|
||||
|
||||
@@ -317,10 +310,7 @@ pub async fn create_account(
|
||||
};
|
||||
|
||||
let session_insert =
|
||||
sqlx::query("INSERT INTO sessions (access_jwt, refresh_jwt, did) VALUES ($1, $2, $3)")
|
||||
.bind(&access_jwt)
|
||||
.bind(&refresh_jwt)
|
||||
.bind(&did)
|
||||
sqlx::query!("INSERT INTO sessions (access_jwt, refresh_jwt, did) VALUES ($1, $2, $3)", access_jwt, refresh_jwt, did)
|
||||
.execute(&mut *tx)
|
||||
.await;
|
||||
|
||||
|
||||
+14
-35
@@ -11,7 +11,6 @@ use k256::elliptic_curve::sec1::ToEncodedPoint;
|
||||
use reqwest;
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use sqlx::Row;
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -33,15 +32,13 @@ pub async fn resolve_handle(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let user = sqlx::query("SELECT did FROM users WHERE handle = $1")
|
||||
.bind(handle)
|
||||
let user = sqlx::query!("SELECT did FROM users WHERE handle = $1", handle)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match user {
|
||||
Ok(Some(row)) => {
|
||||
let did: String = row.get("did");
|
||||
(StatusCode::OK, Json(json!({ "did": did }))).into_response()
|
||||
(StatusCode::OK, Json(json!({ "did": row.did }))).into_response()
|
||||
}
|
||||
Ok(None) => (
|
||||
StatusCode::NOT_FOUND,
|
||||
@@ -97,17 +94,12 @@ pub async fn well_known_did(State(_state): State<AppState>) -> impl IntoResponse
|
||||
pub async fn user_did_doc(State(state): State<AppState>, Path(handle): Path<String>) -> Response {
|
||||
let hostname = std::env::var("PDS_HOSTNAME").unwrap_or_else(|_| "localhost".to_string());
|
||||
|
||||
let user = sqlx::query("SELECT id, did FROM users WHERE handle = $1")
|
||||
.bind(&handle)
|
||||
let user = sqlx::query!("SELECT id, did FROM users WHERE handle = $1", handle)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (user_id, did) = match user {
|
||||
Ok(Some(row)) => {
|
||||
let id: uuid::Uuid = row.get("id");
|
||||
let d: String = row.get("did");
|
||||
(id, d)
|
||||
}
|
||||
Ok(Some(row)) => (row.id, row.did),
|
||||
Ok(None) => {
|
||||
return (StatusCode::NOT_FOUND, Json(json!({"error": "NotFound"}))).into_response();
|
||||
}
|
||||
@@ -129,13 +121,12 @@ pub async fn user_did_doc(State(state): State<AppState>, Path(handle): Path<Stri
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let key_row = sqlx::query("SELECT key_bytes FROM user_keys WHERE user_id = $1")
|
||||
.bind(user_id)
|
||||
let key_row = sqlx::query!("SELECT key_bytes FROM user_keys WHERE user_id = $1", user_id)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let key_bytes: Vec<u8> = match key_row {
|
||||
Ok(Some(row)) => row.get("key_bytes"),
|
||||
Ok(Some(row)) => row.key_bytes,
|
||||
_ => {
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
@@ -294,7 +285,7 @@ pub async fn get_recommended_did_credentials(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes, u.handle
|
||||
FROM sessions s
|
||||
@@ -302,17 +293,13 @@ pub async fn get_recommended_did_credentials(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (_did, key_bytes, handle) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
row.get::<String, _>("handle"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes, row.handle),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -404,7 +391,7 @@ pub async fn update_handle(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes, u.id as user_id
|
||||
FROM sessions s
|
||||
@@ -412,17 +399,13 @@ pub async fn update_handle(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (_did, key_bytes, user_id) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
row.get::<uuid::Uuid, _>("user_id"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes, row.user_id),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -468,9 +451,7 @@ pub async fn update_handle(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let existing = sqlx::query("SELECT id FROM users WHERE handle = $1 AND id != $2")
|
||||
.bind(new_handle)
|
||||
.bind(user_id)
|
||||
let existing = sqlx::query!("SELECT id FROM users WHERE handle = $1 AND id != $2", new_handle, user_id)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -482,9 +463,7 @@ pub async fn update_handle(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query("UPDATE users SET handle = $1 WHERE id = $2")
|
||||
.bind(new_handle)
|
||||
.bind(user_id)
|
||||
let result = sqlx::query!("UPDATE users SET handle = $1 WHERE id = $2", new_handle, user_id)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
|
||||
+12
-15
@@ -7,7 +7,6 @@ use axum::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
use sqlx::Row;
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -49,7 +48,7 @@ pub async fn create_report(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes
|
||||
FROM sessions s
|
||||
@@ -57,16 +56,13 @@ pub async fn create_report(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (did, key_bytes) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -113,15 +109,16 @@ pub async fn create_report(
|
||||
let created_at = chrono::Utc::now();
|
||||
let report_id = created_at.timestamp_millis();
|
||||
|
||||
let insert = sqlx::query(
|
||||
"INSERT INTO reports (id, reason_type, reason, subject_json, reported_by_did, created_at) VALUES ($1, $2, $3, $4, $5, $6)"
|
||||
let subject_json = json!(input.subject);
|
||||
let insert = sqlx::query!(
|
||||
"INSERT INTO reports (id, reason_type, reason, subject_json, reported_by_did, created_at) VALUES ($1, $2, $3, $4, $5, $6)",
|
||||
report_id,
|
||||
input.reason_type,
|
||||
input.reason,
|
||||
subject_json,
|
||||
did,
|
||||
created_at
|
||||
)
|
||||
.bind(report_id)
|
||||
.bind(&input.reason_type)
|
||||
.bind(&input.reason)
|
||||
.bind(json!(input.subject))
|
||||
.bind(&did)
|
||||
.bind(created_at)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
|
||||
+2
-5
@@ -6,7 +6,6 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use reqwest::Client;
|
||||
use sqlx::Row;
|
||||
use std::collections::HashMap;
|
||||
use tracing::{error, info};
|
||||
|
||||
@@ -48,15 +47,13 @@ pub async fn proxy_handler(
|
||||
if let Ok(token) = auth_val.to_str() {
|
||||
let token = token.replace("Bearer ", "");
|
||||
if let Ok(did) = crate::auth::get_did_from_token(&token) {
|
||||
let key_row = sqlx::query("SELECT k.key_bytes FROM user_keys k JOIN users u ON k.user_id = u.id WHERE u.did = $1")
|
||||
.bind(&did)
|
||||
let key_row = sqlx::query!("SELECT k.key_bytes FROM user_keys k JOIN users u ON k.user_id = u.id WHERE u.did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
if let Ok(Some(row)) = key_row {
|
||||
let key_bytes: Vec<u8> = row.get("key_bytes");
|
||||
if let Ok(new_token) =
|
||||
crate::auth::create_service_token(&did, aud, &method, &key_bytes)
|
||||
crate::auth::create_service_token(&did, aud, &method, &row.key_bytes)
|
||||
{
|
||||
if let Ok(val) =
|
||||
axum::http::HeaderValue::from_str(&format!("Bearer {}", new_token))
|
||||
|
||||
+31
-42
@@ -12,7 +12,6 @@ use multihash::Multihash;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sha2::{Digest, Sha256};
|
||||
use sqlx::Row;
|
||||
use std::str::FromStr;
|
||||
use tracing::error;
|
||||
|
||||
@@ -35,19 +34,16 @@ pub async fn upload_blob(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
"SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.access_jwt = $1"
|
||||
let session = sqlx::query!(
|
||||
"SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.access_jwt = $1",
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await
|
||||
.unwrap_or(None);
|
||||
|
||||
let (did, key_bytes) = match session {
|
||||
Some(row) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
),
|
||||
Some(row) => (row.did, row.key_bytes),
|
||||
None => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -92,13 +88,12 @@ pub async fn upload_blob(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let user_query = sqlx::query("SELECT id FROM users WHERE did = $1")
|
||||
.bind(&did)
|
||||
let user_query = sqlx::query!("SELECT id FROM users WHERE did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let user_id: uuid::Uuid = match user_query {
|
||||
Ok(Some(row)) => row.get("id"),
|
||||
let user_id = match user_query {
|
||||
Ok(Some(row)) => row.id,
|
||||
_ => {
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
@@ -108,14 +103,14 @@ pub async fn upload_blob(
|
||||
}
|
||||
};
|
||||
|
||||
let insert = sqlx::query(
|
||||
"INSERT INTO blobs (cid, mime_type, size_bytes, created_by_user, storage_key) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (cid) DO NOTHING"
|
||||
let insert = sqlx::query!(
|
||||
"INSERT INTO blobs (cid, mime_type, size_bytes, created_by_user, storage_key) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (cid) DO NOTHING",
|
||||
cid_str,
|
||||
mime_type,
|
||||
size,
|
||||
user_id,
|
||||
storage_key
|
||||
)
|
||||
.bind(&cid_str)
|
||||
.bind(&mime_type)
|
||||
.bind(size)
|
||||
.bind(user_id)
|
||||
.bind(&storage_key)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -202,19 +197,16 @@ pub async fn list_missing_blobs(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
"SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.access_jwt = $1"
|
||||
let session = sqlx::query!(
|
||||
"SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.access_jwt = $1",
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await
|
||||
.unwrap_or(None);
|
||||
|
||||
let (did, key_bytes) = match session {
|
||||
Some(row) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
),
|
||||
Some(row) => (row.did, row.key_bytes),
|
||||
None => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -232,13 +224,12 @@ pub async fn list_missing_blobs(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let user_query = sqlx::query("SELECT id FROM users WHERE did = $1")
|
||||
.bind(&did)
|
||||
let user_query = sqlx::query!("SELECT id FROM users WHERE did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let user_id: uuid::Uuid = match user_query {
|
||||
Ok(Some(row)) => row.get("id"),
|
||||
let user_id = match user_query {
|
||||
Ok(Some(row)) => row.id,
|
||||
_ => {
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
@@ -257,13 +248,13 @@ pub async fn list_missing_blobs(
|
||||
(String::new(), String::new())
|
||||
};
|
||||
|
||||
let records_query = sqlx::query(
|
||||
"SELECT collection, rkey, record_cid FROM records WHERE repo_id = $1 AND (collection, rkey) > ($2, $3) ORDER BY collection, rkey LIMIT $4"
|
||||
let records_query = sqlx::query!(
|
||||
"SELECT collection, rkey, record_cid FROM records WHERE repo_id = $1 AND (collection, rkey) > ($2, $3) ORDER BY collection, rkey LIMIT $4",
|
||||
user_id,
|
||||
cursor_collection,
|
||||
cursor_rkey,
|
||||
limit
|
||||
)
|
||||
.bind(user_id)
|
||||
.bind(cursor_collection)
|
||||
.bind(cursor_rkey)
|
||||
.bind(limit)
|
||||
.fetch_all(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -283,9 +274,9 @@ pub async fn list_missing_blobs(
|
||||
let mut last_cursor = None;
|
||||
|
||||
for row in &records {
|
||||
let collection: String = row.get("collection");
|
||||
let rkey: String = row.get("rkey");
|
||||
let record_cid_str: String = row.get("record_cid");
|
||||
let collection = &row.collection;
|
||||
let rkey = &row.rkey;
|
||||
let record_cid_str = &row.record_cid;
|
||||
|
||||
last_cursor = Some(format!("{}|{}", collection, rkey));
|
||||
|
||||
@@ -308,9 +299,7 @@ pub async fn list_missing_blobs(
|
||||
find_blobs(&record_val, &mut blobs);
|
||||
|
||||
for blob_cid_str in blobs {
|
||||
let exists = sqlx::query("SELECT 1 FROM blobs WHERE cid = $1 AND created_by_user = $2")
|
||||
.bind(&blob_cid_str)
|
||||
.bind(user_id)
|
||||
let exists = sqlx::query!("SELECT 1 as one FROM blobs WHERE cid = $1 AND created_by_user = $2", blob_cid_str, user_id)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ pub async fn describe_server() -> impl IntoResponse {
|
||||
}
|
||||
|
||||
pub async fn health(State(state): State<AppState>) -> impl IntoResponse {
|
||||
match sqlx::query("SELECT 1").execute(&state.db).await {
|
||||
match sqlx::query!("SELECT 1 as one").fetch_one(&state.db).await {
|
||||
Ok(_) => (StatusCode::OK, "OK"),
|
||||
Err(e) => {
|
||||
error!("Health check failed: {:?}", e);
|
||||
|
||||
+81
-127
@@ -8,7 +8,6 @@ use axum::{
|
||||
use bcrypt::verify;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::Row;
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -43,7 +42,7 @@ pub async fn get_service_auth(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes
|
||||
FROM sessions s
|
||||
@@ -51,16 +50,13 @@ pub async fn get_service_auth(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (did, key_bytes) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -125,31 +121,31 @@ pub async fn create_session(
|
||||
) -> Response {
|
||||
info!("create_session: identifier='{}'", input.identifier);
|
||||
|
||||
let user_row = sqlx::query("SELECT u.id, u.did, u.handle, u.password_hash, k.key_bytes FROM users u JOIN user_keys k ON u.id = k.user_id WHERE u.handle = $1 OR u.email = $1")
|
||||
.bind(&input.identifier)
|
||||
let user_row = sqlx::query!(
|
||||
"SELECT u.id, u.did, u.handle, u.password_hash, k.key_bytes FROM users u JOIN user_keys k ON u.id = k.user_id WHERE u.handle = $1 OR u.email = $1",
|
||||
input.identifier
|
||||
)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match user_row {
|
||||
Ok(Some(row)) => {
|
||||
let user_id: uuid::Uuid = row.get("id");
|
||||
let stored_hash: String = row.get("password_hash");
|
||||
let did: String = row.get("did");
|
||||
let handle: String = row.get("handle");
|
||||
let key_bytes: Vec<u8> = row.get("key_bytes");
|
||||
let user_id = row.id;
|
||||
let stored_hash = &row.password_hash;
|
||||
let did = &row.did;
|
||||
let handle = &row.handle;
|
||||
let key_bytes = &row.key_bytes;
|
||||
|
||||
let password_valid = if verify(&input.password, &stored_hash).unwrap_or(false) {
|
||||
let password_valid = if verify(&input.password, stored_hash).unwrap_or(false) {
|
||||
true
|
||||
} else {
|
||||
let app_pass_rows = sqlx::query("SELECT password_hash FROM app_passwords WHERE user_id = $1")
|
||||
.bind(user_id)
|
||||
let app_pass_rows = sqlx::query!("SELECT password_hash FROM app_passwords WHERE user_id = $1", user_id)
|
||||
.fetch_all(&state.db)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
app_pass_rows.iter().any(|row| {
|
||||
let hash: String = row.get("password_hash");
|
||||
verify(&input.password, &hash).unwrap_or(false)
|
||||
verify(&input.password, &row.password_hash).unwrap_or(false)
|
||||
})
|
||||
};
|
||||
|
||||
@@ -178,12 +174,12 @@ pub async fn create_session(
|
||||
}
|
||||
};
|
||||
|
||||
let session_insert = sqlx::query(
|
||||
let session_insert = sqlx::query!(
|
||||
"INSERT INTO sessions (access_jwt, refresh_jwt, did) VALUES ($1, $2, $3)",
|
||||
access_jwt,
|
||||
refresh_jwt,
|
||||
did
|
||||
)
|
||||
.bind(&access_jwt)
|
||||
.bind(&refresh_jwt)
|
||||
.bind(&did)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -194,8 +190,8 @@ pub async fn create_session(
|
||||
Json(CreateSessionOutput {
|
||||
access_jwt,
|
||||
refresh_jwt,
|
||||
handle,
|
||||
did,
|
||||
handle: handle.clone(),
|
||||
did: did.clone(),
|
||||
}),
|
||||
)
|
||||
.into_response();
|
||||
@@ -255,7 +251,7 @@ pub async fn get_session(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let result = sqlx::query(
|
||||
let result = sqlx::query!(
|
||||
r#"
|
||||
SELECT u.handle, u.did, u.email, k.key_bytes
|
||||
FROM sessions s
|
||||
@@ -263,28 +259,23 @@ pub async fn get_session(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(Some(row)) => {
|
||||
let handle: String = row.get("handle");
|
||||
let did: String = row.get("did");
|
||||
let email: String = row.get("email");
|
||||
let key_bytes: Vec<u8> = row.get("key_bytes");
|
||||
|
||||
if let Err(_) = crate::auth::verify_token(&token, &key_bytes) {
|
||||
if let Err(_) = crate::auth::verify_token(&token, &row.key_bytes) {
|
||||
return (StatusCode::UNAUTHORIZED, Json(json!({"error": "AuthenticationFailed", "message": "Invalid token signature"}))).into_response();
|
||||
}
|
||||
|
||||
return (
|
||||
StatusCode::OK,
|
||||
Json(json!({
|
||||
"handle": handle,
|
||||
"did": did,
|
||||
"email": email,
|
||||
"handle": row.handle,
|
||||
"did": row.did,
|
||||
"email": row.email,
|
||||
"didDoc": {}
|
||||
})),
|
||||
)
|
||||
@@ -327,8 +318,7 @@ pub async fn delete_session(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let result = sqlx::query("DELETE FROM sessions WHERE access_jwt = $1")
|
||||
.bind(token)
|
||||
let result = sqlx::query!("DELETE FROM sessions WHERE access_jwt = $1", token)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -369,17 +359,17 @@ pub async fn refresh_session(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
"SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.refresh_jwt = $1"
|
||||
let session = sqlx::query!(
|
||||
"SELECT s.did, k.key_bytes FROM sessions s JOIN users u ON s.did = u.did JOIN user_keys k ON u.id = k.user_id WHERE s.refresh_jwt = $1",
|
||||
refresh_token
|
||||
)
|
||||
.bind(&refresh_token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match session {
|
||||
Ok(Some(session_row)) => {
|
||||
let did: String = session_row.get("did");
|
||||
let key_bytes: Vec<u8> = session_row.get("key_bytes");
|
||||
let did = &session_row.did;
|
||||
let key_bytes = &session_row.key_bytes;
|
||||
|
||||
if let Err(_) = crate::auth::verify_token(&refresh_token, &key_bytes) {
|
||||
return (StatusCode::UNAUTHORIZED, Json(json!({"error": "AuthenticationFailed", "message": "Invalid refresh token signature"}))).into_response();
|
||||
@@ -408,31 +398,29 @@ pub async fn refresh_session(
|
||||
}
|
||||
};
|
||||
|
||||
let update = sqlx::query(
|
||||
let update = sqlx::query!(
|
||||
"UPDATE sessions SET access_jwt = $1, refresh_jwt = $2 WHERE refresh_jwt = $3",
|
||||
new_access_jwt,
|
||||
new_refresh_jwt,
|
||||
refresh_token
|
||||
)
|
||||
.bind(&new_access_jwt)
|
||||
.bind(&new_refresh_jwt)
|
||||
.bind(&refresh_token)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
match update {
|
||||
Ok(_) => {
|
||||
let user = sqlx::query("SELECT handle FROM users WHERE did = $1")
|
||||
.bind(&did)
|
||||
let user = sqlx::query!("SELECT handle FROM users WHERE did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match user {
|
||||
Ok(Some(u)) => {
|
||||
let handle: String = u.get("handle");
|
||||
return (
|
||||
StatusCode::OK,
|
||||
Json(json!({
|
||||
"accessJwt": new_access_jwt,
|
||||
"refreshJwt": new_refresh_jwt,
|
||||
"handle": handle,
|
||||
"handle": u.handle,
|
||||
"did": did
|
||||
})),
|
||||
)
|
||||
@@ -517,7 +505,7 @@ pub async fn check_account_status(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes, u.id as user_id
|
||||
FROM sessions s
|
||||
@@ -525,17 +513,13 @@ pub async fn check_account_status(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (did, key_bytes, user_id) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
row.get::<uuid::Uuid, _>("user_id"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes, row.user_id),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -561,37 +545,35 @@ pub async fn check_account_status(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let user_status = sqlx::query("SELECT deactivated_at FROM users WHERE did = $1")
|
||||
.bind(&did)
|
||||
let user_status = sqlx::query!("SELECT deactivated_at FROM users WHERE did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let deactivated_at: Option<chrono::DateTime<chrono::Utc>> = match user_status {
|
||||
Ok(Some(row)) => row.get("deactivated_at"),
|
||||
let deactivated_at = match user_status {
|
||||
Ok(Some(row)) => row.deactivated_at,
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let repo_result = sqlx::query("SELECT repo_root_cid FROM repos WHERE user_id = $1")
|
||||
.bind(user_id)
|
||||
let repo_result = sqlx::query!("SELECT repo_root_cid FROM repos WHERE user_id = $1", user_id)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let repo_commit = match repo_result {
|
||||
Ok(Some(row)) => row.get::<String, _>("repo_root_cid"),
|
||||
Ok(Some(row)) => row.repo_root_cid,
|
||||
_ => String::new(),
|
||||
};
|
||||
|
||||
let record_count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM records WHERE repo_id = $1")
|
||||
.bind(user_id)
|
||||
let record_count: i64 = sqlx::query_scalar!("SELECT COUNT(*) FROM records WHERE repo_id = $1", user_id)
|
||||
.fetch_one(&state.db)
|
||||
.await
|
||||
.unwrap_or(Some(0))
|
||||
.unwrap_or(0);
|
||||
|
||||
let blob_count: i64 =
|
||||
sqlx::query_scalar("SELECT COUNT(*) FROM blobs WHERE created_by_user = $1")
|
||||
.bind(user_id)
|
||||
sqlx::query_scalar!("SELECT COUNT(*) FROM blobs WHERE created_by_user = $1", user_id)
|
||||
.fetch_one(&state.db)
|
||||
.await
|
||||
.unwrap_or(Some(0))
|
||||
.unwrap_or(0);
|
||||
|
||||
let valid_did = did.starts_with("did:");
|
||||
@@ -632,7 +614,7 @@ pub async fn activate_account(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes
|
||||
FROM sessions s
|
||||
@@ -640,16 +622,13 @@ pub async fn activate_account(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (did, key_bytes) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -675,8 +654,7 @@ pub async fn activate_account(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query("UPDATE users SET deactivated_at = NULL WHERE did = $1")
|
||||
.bind(&did)
|
||||
let result = sqlx::query!("UPDATE users SET deactivated_at = NULL WHERE did = $1", did)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -719,7 +697,7 @@ pub async fn deactivate_account(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes
|
||||
FROM sessions s
|
||||
@@ -727,16 +705,13 @@ pub async fn deactivate_account(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (did, key_bytes) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -762,8 +737,7 @@ pub async fn deactivate_account(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query("UPDATE users SET deactivated_at = NOW() WHERE did = $1")
|
||||
.bind(&did)
|
||||
let result = sqlx::query!("UPDATE users SET deactivated_at = NOW() WHERE did = $1", did)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -812,7 +786,7 @@ pub async fn list_app_passwords(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes, u.id as user_id
|
||||
FROM sessions s
|
||||
@@ -820,17 +794,13 @@ pub async fn list_app_passwords(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (_did, key_bytes, user_id) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
row.get::<uuid::Uuid, _>("user_id"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes, row.user_id),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -856,8 +826,7 @@ pub async fn list_app_passwords(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query("SELECT name, created_at, privileged FROM app_passwords WHERE user_id = $1 ORDER BY created_at DESC")
|
||||
.bind(user_id)
|
||||
let result = sqlx::query!("SELECT name, created_at, privileged FROM app_passwords WHERE user_id = $1 ORDER BY created_at DESC", user_id)
|
||||
.fetch_all(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -866,13 +835,10 @@ pub async fn list_app_passwords(
|
||||
let passwords: Vec<AppPassword> = rows
|
||||
.iter()
|
||||
.map(|row| {
|
||||
let name: String = row.get("name");
|
||||
let created_at: chrono::DateTime<chrono::Utc> = row.get("created_at");
|
||||
let privileged: bool = row.get("privileged");
|
||||
AppPassword {
|
||||
name,
|
||||
created_at: created_at.to_rfc3339(),
|
||||
privileged,
|
||||
name: row.name.clone(),
|
||||
created_at: row.created_at.to_rfc3339(),
|
||||
privileged: row.privileged,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -925,7 +891,7 @@ pub async fn create_app_password(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes, u.id as user_id
|
||||
FROM sessions s
|
||||
@@ -933,17 +899,13 @@ pub async fn create_app_password(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (_did, key_bytes, user_id) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
row.get::<uuid::Uuid, _>("user_id"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes, row.user_id),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -978,9 +940,7 @@ pub async fn create_app_password(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let existing = sqlx::query("SELECT id FROM app_passwords WHERE user_id = $1 AND name = $2")
|
||||
.bind(user_id)
|
||||
.bind(name)
|
||||
let existing = sqlx::query!("SELECT id FROM app_passwords WHERE user_id = $1 AND name = $2", user_id, name)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -1017,14 +977,14 @@ pub async fn create_app_password(
|
||||
let privileged = input.privileged.unwrap_or(false);
|
||||
let created_at = chrono::Utc::now();
|
||||
|
||||
let result = sqlx::query(
|
||||
"INSERT INTO app_passwords (user_id, name, password_hash, created_at, privileged) VALUES ($1, $2, $3, $4, $5)"
|
||||
let result = sqlx::query!(
|
||||
"INSERT INTO app_passwords (user_id, name, password_hash, created_at, privileged) VALUES ($1, $2, $3, $4, $5)",
|
||||
user_id,
|
||||
name,
|
||||
password_hash,
|
||||
created_at,
|
||||
privileged
|
||||
)
|
||||
.bind(user_id)
|
||||
.bind(name)
|
||||
.bind(&password_hash)
|
||||
.bind(created_at)
|
||||
.bind(privileged)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -1075,7 +1035,7 @@ pub async fn revoke_app_password(
|
||||
.unwrap_or("")
|
||||
.replace("Bearer ", "");
|
||||
|
||||
let session = sqlx::query(
|
||||
let session = sqlx::query!(
|
||||
r#"
|
||||
SELECT s.did, k.key_bytes, u.id as user_id
|
||||
FROM sessions s
|
||||
@@ -1083,17 +1043,13 @@ pub async fn revoke_app_password(
|
||||
JOIN user_keys k ON u.id = k.user_id
|
||||
WHERE s.access_jwt = $1
|
||||
"#,
|
||||
token
|
||||
)
|
||||
.bind(&token)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let (_did, key_bytes, user_id) = match session {
|
||||
Ok(Some(row)) => (
|
||||
row.get::<String, _>("did"),
|
||||
row.get::<Vec<u8>, _>("key_bytes"),
|
||||
row.get::<uuid::Uuid, _>("user_id"),
|
||||
),
|
||||
Ok(Some(row)) => (row.did, row.key_bytes, row.user_id),
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
@@ -1128,9 +1084,7 @@ pub async fn revoke_app_password(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query("DELETE FROM app_passwords WHERE user_id = $1 AND name = $2")
|
||||
.bind(user_id)
|
||||
.bind(name)
|
||||
let result = sqlx::query!("DELETE FROM app_passwords WHERE user_id = $1 AND name = $2", user_id, name)
|
||||
.execute(&state.db)
|
||||
.await;
|
||||
|
||||
|
||||
+9
-15
@@ -5,7 +5,7 @@ use jacquard_repo::repo::CommitData;
|
||||
use jacquard_repo::storage::BlockStore;
|
||||
use multihash::Multihash;
|
||||
use sha2::{Digest, Sha256};
|
||||
use sqlx::{PgPool, Row};
|
||||
use sqlx::PgPool;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PostgresBlockStore {
|
||||
@@ -21,17 +21,13 @@ impl PostgresBlockStore {
|
||||
impl BlockStore for PostgresBlockStore {
|
||||
async fn get(&self, cid: &Cid) -> Result<Option<Bytes>, RepoError> {
|
||||
let cid_bytes = cid.to_bytes();
|
||||
let row = sqlx::query("SELECT data FROM blocks WHERE cid = $1")
|
||||
.bind(cid_bytes)
|
||||
let row = sqlx::query!("SELECT data FROM blocks WHERE cid = $1", &cid_bytes)
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.map_err(|e| RepoError::storage(e))?;
|
||||
|
||||
match row {
|
||||
Some(row) => {
|
||||
let data: Vec<u8> = row.get("data");
|
||||
Ok(Some(Bytes::from(data)))
|
||||
}
|
||||
Some(row) => Ok(Some(Bytes::from(row.data))),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
@@ -44,9 +40,7 @@ impl BlockStore for PostgresBlockStore {
|
||||
let cid = Cid::new_v1(0x71, multihash);
|
||||
let cid_bytes = cid.to_bytes();
|
||||
|
||||
sqlx::query("INSERT INTO blocks (cid, data) VALUES ($1, $2) ON CONFLICT (cid) DO NOTHING")
|
||||
.bind(cid_bytes)
|
||||
.bind(data)
|
||||
sqlx::query!("INSERT INTO blocks (cid, data) VALUES ($1, $2) ON CONFLICT (cid) DO NOTHING", &cid_bytes, data)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_err(|e| RepoError::storage(e))?;
|
||||
@@ -56,8 +50,7 @@ impl BlockStore for PostgresBlockStore {
|
||||
|
||||
async fn has(&self, cid: &Cid) -> Result<bool, RepoError> {
|
||||
let cid_bytes = cid.to_bytes();
|
||||
let row = sqlx::query("SELECT 1 FROM blocks WHERE cid = $1")
|
||||
.bind(cid_bytes)
|
||||
let row = sqlx::query!("SELECT 1 as one FROM blocks WHERE cid = $1", &cid_bytes)
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.map_err(|e| RepoError::storage(e))?;
|
||||
@@ -72,11 +65,12 @@ impl BlockStore for PostgresBlockStore {
|
||||
let blocks: Vec<_> = blocks.into_iter().collect();
|
||||
for (cid, data) in blocks {
|
||||
let cid_bytes = cid.to_bytes();
|
||||
sqlx::query(
|
||||
let data_ref = data.as_ref();
|
||||
sqlx::query!(
|
||||
"INSERT INTO blocks (cid, data) VALUES ($1, $2) ON CONFLICT (cid) DO NOTHING",
|
||||
&cid_bytes,
|
||||
data_ref
|
||||
)
|
||||
.bind(cid_bytes)
|
||||
.bind(data.as_ref())
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_err(|e| RepoError::storage(e))?;
|
||||
|
||||
+39
-45
@@ -9,7 +9,6 @@ use axum::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::Row;
|
||||
use tracing::{error, info};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -37,25 +36,24 @@ pub async fn get_latest_commit(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query(
|
||||
let result = sqlx::query!(
|
||||
r#"
|
||||
SELECT r.repo_root_cid
|
||||
FROM repos r
|
||||
JOIN users u ON r.user_id = u.id
|
||||
WHERE u.did = $1
|
||||
"#,
|
||||
did
|
||||
)
|
||||
.bind(did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(Some(row)) => {
|
||||
let cid: String = row.get("repo_root_cid");
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(GetLatestCommitOutput {
|
||||
cid,
|
||||
cid: row.repo_root_cid,
|
||||
rev: chrono::Utc::now().timestamp_millis().to_string(),
|
||||
}),
|
||||
)
|
||||
@@ -105,7 +103,7 @@ pub async fn list_repos(
|
||||
let limit = params.limit.unwrap_or(50).min(1000);
|
||||
let cursor_did = params.cursor.as_deref().unwrap_or("");
|
||||
|
||||
let result = sqlx::query(
|
||||
let result = sqlx::query!(
|
||||
r#"
|
||||
SELECT u.did, r.repo_root_cid
|
||||
FROM repos r
|
||||
@@ -114,9 +112,9 @@ pub async fn list_repos(
|
||||
ORDER BY u.did ASC
|
||||
LIMIT $2
|
||||
"#,
|
||||
cursor_did,
|
||||
limit + 1
|
||||
)
|
||||
.bind(cursor_did)
|
||||
.bind(limit + 1)
|
||||
.fetch_all(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -127,11 +125,9 @@ pub async fn list_repos(
|
||||
.iter()
|
||||
.take(limit as usize)
|
||||
.map(|row| {
|
||||
let did: String = row.get("did");
|
||||
let head: String = row.get("repo_root_cid");
|
||||
RepoInfo {
|
||||
did,
|
||||
head,
|
||||
did: row.did.clone(),
|
||||
head: row.repo_root_cid.clone(),
|
||||
rev: chrono::Utc::now().timestamp_millis().to_string(),
|
||||
active: true,
|
||||
}
|
||||
@@ -193,8 +189,7 @@ pub async fn get_blob(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let user_exists = sqlx::query("SELECT id FROM users WHERE did = $1")
|
||||
.bind(did)
|
||||
let user_exists = sqlx::query!("SELECT id FROM users WHERE did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
@@ -217,15 +212,14 @@ pub async fn get_blob(
|
||||
Ok(Some(_)) => {}
|
||||
}
|
||||
|
||||
let blob_result = sqlx::query("SELECT storage_key, mime_type FROM blobs WHERE cid = $1")
|
||||
.bind(cid)
|
||||
let blob_result = sqlx::query!("SELECT storage_key, mime_type FROM blobs WHERE cid = $1", cid)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match blob_result {
|
||||
Ok(Some(row)) => {
|
||||
let storage_key: String = row.get("storage_key");
|
||||
let mime_type: String = row.get("mime_type");
|
||||
let storage_key = &row.storage_key;
|
||||
let mime_type = &row.mime_type;
|
||||
|
||||
match state.blob_store.get(&storage_key).await {
|
||||
Ok(data) => Response::builder()
|
||||
@@ -290,13 +284,12 @@ pub async fn list_blobs(
|
||||
let limit = params.limit.unwrap_or(500).min(1000);
|
||||
let cursor_cid = params.cursor.as_deref().unwrap_or("");
|
||||
|
||||
let user_result = sqlx::query("SELECT id FROM users WHERE did = $1")
|
||||
.bind(did)
|
||||
let user_result = sqlx::query!("SELECT id FROM users WHERE did = $1", did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
let user_id: uuid::Uuid = match user_result {
|
||||
Ok(Some(row)) => row.get("id"),
|
||||
let user_id = match user_result {
|
||||
Ok(Some(row)) => row.id,
|
||||
Ok(None) => {
|
||||
return (
|
||||
StatusCode::NOT_FOUND,
|
||||
@@ -314,44 +307,48 @@ pub async fn list_blobs(
|
||||
}
|
||||
};
|
||||
|
||||
let result = if let Some(since) = ¶ms.since {
|
||||
sqlx::query(
|
||||
let cids_result: Result<Vec<String>, sqlx::Error> = if let Some(since) = ¶ms.since {
|
||||
let since_time = chrono::DateTime::parse_from_rfc3339(since)
|
||||
.map(|dt| dt.with_timezone(&chrono::Utc))
|
||||
.unwrap_or_else(|_| chrono::Utc::now());
|
||||
sqlx::query!(
|
||||
r#"
|
||||
SELECT cid FROM blobs
|
||||
WHERE created_by_user = $1 AND cid > $2 AND created_at > $3
|
||||
ORDER BY cid ASC
|
||||
LIMIT $4
|
||||
"#,
|
||||
user_id,
|
||||
cursor_cid,
|
||||
since_time,
|
||||
limit + 1
|
||||
)
|
||||
.bind(user_id)
|
||||
.bind(cursor_cid)
|
||||
.bind(since)
|
||||
.bind(limit + 1)
|
||||
.fetch_all(&state.db)
|
||||
.await
|
||||
.map(|rows| rows.into_iter().map(|r| r.cid).collect())
|
||||
} else {
|
||||
sqlx::query(
|
||||
sqlx::query!(
|
||||
r#"
|
||||
SELECT cid FROM blobs
|
||||
WHERE created_by_user = $1 AND cid > $2
|
||||
ORDER BY cid ASC
|
||||
LIMIT $3
|
||||
"#,
|
||||
user_id,
|
||||
cursor_cid,
|
||||
limit + 1
|
||||
)
|
||||
.bind(user_id)
|
||||
.bind(cursor_cid)
|
||||
.bind(limit + 1)
|
||||
.fetch_all(&state.db)
|
||||
.await
|
||||
.map(|rows| rows.into_iter().map(|r| r.cid).collect())
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(rows) => {
|
||||
let has_more = rows.len() as i64 > limit;
|
||||
let cids: Vec<String> = rows
|
||||
.iter()
|
||||
match cids_result {
|
||||
Ok(cids) => {
|
||||
let has_more = cids.len() as i64 > limit;
|
||||
let cids: Vec<String> = cids
|
||||
.into_iter()
|
||||
.take(limit as usize)
|
||||
.map(|row| row.get("cid"))
|
||||
.collect();
|
||||
|
||||
let next_cursor = if has_more {
|
||||
@@ -406,29 +403,26 @@ pub async fn get_repo_status(
|
||||
.into_response();
|
||||
}
|
||||
|
||||
let result = sqlx::query(
|
||||
let result = sqlx::query!(
|
||||
r#"
|
||||
SELECT u.did, r.repo_root_cid
|
||||
FROM users u
|
||||
LEFT JOIN repos r ON u.id = r.user_id
|
||||
WHERE u.did = $1
|
||||
"#,
|
||||
did
|
||||
)
|
||||
.bind(did)
|
||||
.fetch_optional(&state.db)
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(Some(row)) => {
|
||||
let user_did: String = row.get("did");
|
||||
let repo_root: Option<String> = row.get("repo_root_cid");
|
||||
|
||||
let rev = repo_root.map(|_| chrono::Utc::now().timestamp_millis().to_string());
|
||||
let rev = Some(chrono::Utc::now().timestamp_millis().to_string());
|
||||
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(GetRepoStatusOutput {
|
||||
did: user_did,
|
||||
did: row.did,
|
||||
active: true,
|
||||
rev,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user