WIP on testing SQLite data store

This commit is contained in:
2024-01-03 22:29:27 -05:00
parent dee2222eb1
commit b69b6c37a4
10 changed files with 19 additions and 23 deletions

View File

@@ -24,7 +24,7 @@ type SQLiteCategoryData(conn: SqliteConnection, ser: JsonSerializer, log: ILogge
let countTopLevel webLogId =
log.LogTrace "Category.countTopLevel"
conn.customScalar
$"{Document.Query.countByWebLog} AND data ->> '{parentIdField}' IS NULL"
$"{Document.Query.countByWebLog Table.Category} AND data ->> '{parentIdField}' IS NULL"
[ webLogParam webLogId ]
(toCount >> int)
@@ -79,11 +79,11 @@ type SQLiteCategoryData(conn: SqliteConnection, ser: JsonSerializer, log: ILogge
match! findById catId webLogId with
| Some cat ->
// Reassign any children to the category's parent category
let! children = conn.countByField Table.Category parentIdField EQ catId
let! children = conn.countByField Table.Category parentIdField EQ (string catId)
if children > 0 then
do! conn.patchByField Table.Category parentIdField EQ catId {| ParentId = cat.ParentId |}
do! conn.patchByField Table.Category parentIdField EQ (string catId) {| ParentId = cat.ParentId |}
// Delete the category off all posts where it is assigned, and the category itself
let catIdField = Post.Empty.CategoryIds
let catIdField = nameof Post.Empty.CategoryIds
let! posts =
conn.customList
$"SELECT data ->> '{Post.Empty.Id}', data -> '{catIdField}'
@@ -94,7 +94,7 @@ type SQLiteCategoryData(conn: SqliteConnection, ser: JsonSerializer, log: ILogge
FROM json_each({Table.Post}.data -> '{catIdField}')
WHERE json_each.value = @id)"
[ idParam catId; webLogParam webLogId ]
(fun rdr -> rdr.GetString(0), Utils.deserialize<string list> ser (rdr.GetString(1)))
(fun rdr -> rdr.GetString 0, Utils.deserialize<string list> ser (rdr.GetString 1))
for postId, cats in posts do
do! conn.patchById
Table.Post postId {| CategoryIds = cats |> List.filter (fun it -> it <> string catId) |}

View File

@@ -255,7 +255,7 @@ module Document =
/// Count documents for the given web log ID
let countByWebLog table (webLogId: WebLogId) conn = backgroundTask {
let! count = Count.byField table "WebLogId" EQ webLogId conn
let! count = Count.byField table "WebLogId" EQ (string webLogId) conn
return int count
}
@@ -265,7 +265,7 @@ module Document =
/// Find documents for the given web log
let findByWebLog<'TDoc> table (webLogId: WebLogId) conn =
Find.byField<'TDoc> table "WebLogId" EQ webLogId conn
Find.byField<'TDoc> table "WebLogId" EQ (string webLogId) conn
/// Functions to support revisions
@@ -302,6 +302,6 @@ module Revisions =
for addRev in toAdd do
do! Custom.nonQuery
$"INSERT INTO {revTable} VALUES (@id, @asOf, @text)"
[ idParam key; sqlParam "asOf" (instantParam addRev.AsOf); sqlParam "@text" addRev.Text ]
[ idParam key; sqlParam "asOf" (instantParam addRev.AsOf); sqlParam "@text" (string addRev.Text) ]
conn
}

View File

@@ -53,7 +53,7 @@ type SQLitePageData(conn: SqliteConnection, log: ILogger) =
let countListed webLogId =
log.LogTrace "Page.countListed"
conn.customScalar
$"""{Document.Query.countByWebLog} AND {Query.whereByField pgListName EQ "'true'"}"""
$"""{Document.Query.countByWebLog Table.Page} AND {Query.whereByField pgListName EQ "'true'"}"""
[ webLogParam webLogId ]
(toCount >> int)
@@ -89,7 +89,7 @@ type SQLitePageData(conn: SqliteConnection, log: ILogger) =
let findByPermalink (permalink: Permalink) webLogId =
log.LogTrace "Page.findByPermalink"
conn.customSingle
$"""{Document.Query.selectByWebLog} AND {Query.whereByField linkName EQ "@link"}"""
$"""{Document.Query.selectByWebLog Table.Page} AND {Query.whereByField linkName EQ "@link"}"""
[ webLogParam webLogId; SqliteParameter("@link", string permalink) ]
fromData<Page>

View File

@@ -47,7 +47,7 @@ type SQLitePostData(conn: SqliteConnection, log: ILogger) =
let countByStatus (status: PostStatus) webLogId =
log.LogTrace "Post.countByStatus"
conn.customScalar
$"""{Document.Query.countByWebLog} AND {Query.whereByField statName EQ "@status"}"""
$"""{Document.Query.countByWebLog Table.Post} AND {Query.whereByField statName EQ "@status"}"""
[ webLogParam webLogId; SqliteParameter("@status", string status) ]
(toCount >> int)

View File

@@ -122,7 +122,7 @@ type SQLiteThemeAssetData(conn : SqliteConnection, log: ILogger) =
$"INSERT INTO {Table.ThemeAsset} (
theme_id, path, updated_on, data
) VALUES (
@themeId, @path, @updatedOn, ZEROBLOB(@dataLength)
@id, @path, @updatedOn, ZEROBLOB(@dataLength)
) ON CONFLICT (theme_id, path) DO UPDATE
SET updated_on = @updatedOn,
data = ZEROBLOB(@dataLength)"