Compare commits
1 Commits
main
...
cache-alia
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52451f85b5 |
@ -1420,7 +1420,8 @@ impl CachedEntry {
|
|||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
INSERT INTO cache (id, data_type, alias, data, expires)
|
MERGE INTO cache AS target
|
||||||
|
USING (
|
||||||
SELECT
|
SELECT
|
||||||
json_extract(value, '$.id') AS id,
|
json_extract(value, '$.id') AS id,
|
||||||
json_extract(value, '$.data_type') AS data_type,
|
json_extract(value, '$.data_type') AS data_type,
|
||||||
@ -1430,16 +1431,45 @@ impl CachedEntry {
|
|||||||
FROM
|
FROM
|
||||||
json_each($1)
|
json_each($1)
|
||||||
WHERE TRUE
|
WHERE TRUE
|
||||||
ON CONFLICT (id, data_type) DO UPDATE SET
|
) as items
|
||||||
alias = excluded.alias,
|
ON target.data_type = items.data_type AND target.alias = items.alias
|
||||||
data = excluded.data,
|
WHEN MATCHED THEN
|
||||||
expires = excluded.expires
|
UPDATE SET id = items.id,
|
||||||
|
data_type = items.data_type,
|
||||||
|
alias = items.alias,
|
||||||
|
data = items.data,
|
||||||
|
expires = items.expires
|
||||||
|
WHEN NOT MATCHED THEN
|
||||||
|
INSERT (id, data_type, alias, data, expires)
|
||||||
|
VALUES (items.id, items.data_type, items.alias, items.data, items.expires)
|
||||||
",
|
",
|
||||||
items,
|
items
|
||||||
)
|
)
|
||||||
.execute(exec)
|
.execute(exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// sqlx::query!(
|
||||||
|
// "
|
||||||
|
// INSERT INTO cache (id, data_type, alias, data, expires)
|
||||||
|
// SELECT
|
||||||
|
// json_extract(value, '$.id') AS id,
|
||||||
|
// json_extract(value, '$.data_type') AS data_type,
|
||||||
|
// json_extract(value, '$.alias') AS alias,
|
||||||
|
// json_extract(value, '$.data') AS data,
|
||||||
|
// json_extract(value, '$.expires') AS expires
|
||||||
|
// FROM
|
||||||
|
// json_each($1)
|
||||||
|
// WHERE TRUE
|
||||||
|
// ON CONFLICT (id, data_type) DO UPDATE SET
|
||||||
|
// alias = excluded.alias,
|
||||||
|
// data = excluded.data,
|
||||||
|
// expires = excluded.expires
|
||||||
|
// ",
|
||||||
|
// items,
|
||||||
|
// )
|
||||||
|
// .execute(exec)
|
||||||
|
// .await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user