Update to new doc library

Still need to remove deprecated calls
This commit is contained in:
2024-08-19 20:30:33 -04:00
parent f4be57b665
commit cd450a05e5
15 changed files with 83 additions and 63 deletions

View File

@@ -3,6 +3,7 @@ namespace MyWebLog.Data.SQLite
open System.Threading.Tasks
open BitBadger.Documents
open BitBadger.Documents.Sqlite
open BitBadger.Documents.Sqlite.Compat
open Microsoft.Data.Sqlite
open Microsoft.Extensions.Logging
open MyWebLog

View File

@@ -229,6 +229,7 @@ let webLogParam (webLogId: WebLogId) =
open BitBadger.Documents
open BitBadger.Documents.Sqlite
open BitBadger.Documents.Sqlite.Compat
open BitBadger.Documents.Sqlite.WithConn
/// Functions for manipulating documents
@@ -243,11 +244,11 @@ module Document =
/// A SELECT query to count documents for a given web log ID
let countByWebLog table =
$"{Query.Count.all table} WHERE {whereByWebLog}"
Query.statementWhere (Query.count table) whereByWebLog
/// A query to select from a table by the document's ID and its web log ID
let selectByIdAndWebLog table =
$"{Query.Find.byId table} AND {whereByWebLog}"
Query.statementWhere (Query.find table) $"""{Query.whereById "@id"} AND {whereByWebLog}"""
/// A query to select from a table by its web log ID
let selectByWebLog table =
@@ -255,7 +256,7 @@ module Document =
/// Count documents for the given web log ID
let countByWebLog table (webLogId: WebLogId) conn = backgroundTask {
let! count = Count.byField table (Field.EQ "WebLogId" (string webLogId)) conn
let! count = Count.byFields table Any [ Field.EQ "WebLogId" (string webLogId) ] conn
return int count
}
@@ -265,7 +266,7 @@ module Document =
/// Find documents for the given web log
let findByWebLog<'TDoc> table (webLogId: WebLogId) conn =
Find.byField<'TDoc> table (Field.EQ "WebLogId" (string webLogId)) conn
Find.byFields<'TDoc> table Any [ Field.EQ "WebLogId" (string webLogId) ] conn
/// Functions to support revisions

View File

@@ -3,6 +3,7 @@ namespace MyWebLog.Data.SQLite
open System.Threading.Tasks
open BitBadger.Documents
open BitBadger.Documents.Sqlite
open BitBadger.Documents.Sqlite.Compat
open Microsoft.Data.Sqlite
open Microsoft.Extensions.Logging
open MyWebLog
@@ -93,7 +94,8 @@ type SQLitePageData(conn: SqliteConnection, log: ILogger) =
match! findById pageId webLogId with
| Some _ ->
do! conn.customNonQuery
$"DELETE FROM {Table.PageRevision} WHERE page_id = @id; {Query.Delete.byId Table.Page}"
$"DELETE FROM {Table.PageRevision} WHERE page_id = @id;
{Query.byId (Query.delete Table.Page) (string pageId)}"
[ idParam pageId ]
return true
| None -> return false

View File

@@ -3,6 +3,7 @@ namespace MyWebLog.Data.SQLite
open System.Threading.Tasks
open BitBadger.Documents
open BitBadger.Documents.Sqlite
open BitBadger.Documents.Sqlite.Compat
open Microsoft.Data.Sqlite
open Microsoft.Extensions.Logging
open MyWebLog
@@ -104,7 +105,7 @@ type SQLitePostData(conn: SqliteConnection, log: ILogger) =
$"""DELETE FROM {Table.PostRevision} WHERE post_id = @id;
DELETE FROM {Table.PostComment}
WHERE {Query.whereByField (Field.EQ (nameof Comment.Empty.PostId) "") "@id"};
{Query.Delete.byId Table.Post}"""
{Query.byId (Query.delete Table.Post) (string postId)}"""
[ idParam postId ]
return true
| None -> return false

View File

@@ -2,6 +2,7 @@ namespace MyWebLog.Data.SQLite
open BitBadger.Documents
open BitBadger.Documents.Sqlite
open BitBadger.Documents.Sqlite.Compat
open Microsoft.Data.Sqlite
open Microsoft.Extensions.Logging
open MyWebLog

View File

@@ -25,10 +25,7 @@ type SQLiteThemeData(conn : SqliteConnection, log: ILogger) =
/// Retrieve all themes (except 'admin'; excludes template text)
let all () =
log.LogTrace "Theme.all"
conn.customList
$"{Query.selectFromTable Table.Theme} WHERE {idField} <> 'admin' ORDER BY {idField}"
[]
withoutTemplateText
conn.customList $"{Query.find Table.Theme} WHERE {idField} <> 'admin' ORDER BY {idField}" [] withoutTemplateText
/// Does a given theme exist?
let exists (themeId: ThemeId) =
@@ -43,7 +40,7 @@ type SQLiteThemeData(conn : SqliteConnection, log: ILogger) =
/// Find a theme by its ID (excludes the text of templates)
let findByIdWithoutText (themeId: ThemeId) =
log.LogTrace "Theme.findByIdWithoutText"
conn.customSingle (Query.Find.byId Table.Theme) [ idParam themeId ] withoutTemplateText
conn.customSingle (Query.byId (Query.find Table.Theme) (string themeId)) [ idParam themeId ] withoutTemplateText
/// Delete a theme by its ID
let delete themeId = backgroundTask {
@@ -51,7 +48,8 @@ type SQLiteThemeData(conn : SqliteConnection, log: ILogger) =
match! findByIdWithoutText themeId with
| Some _ ->
do! conn.customNonQuery
$"DELETE FROM {Table.ThemeAsset} WHERE theme_id = @id; {Query.Delete.byId Table.Theme}"
$"DELETE FROM {Table.ThemeAsset} WHERE theme_id = @id;
{Query.byId (Query.delete Table.Theme) (string themeId)}"
[ idParam themeId ]
return true
| None -> return false

View File

@@ -2,6 +2,7 @@ namespace MyWebLog.Data.SQLite
open BitBadger.Documents
open BitBadger.Documents.Sqlite
open BitBadger.Documents.Sqlite.Compat
open Microsoft.Data.Sqlite
open Microsoft.Extensions.Logging
open MyWebLog

View File

@@ -2,6 +2,7 @@ namespace MyWebLog.Data.SQLite
open BitBadger.Documents
open BitBadger.Documents.Sqlite
open BitBadger.Documents.Sqlite.Compat
open Microsoft.Data.Sqlite
open Microsoft.Extensions.Logging
open MyWebLog