From cd450a05e56d673c9560729c790f4febd310124f Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Mon, 19 Aug 2024 20:30:33 -0400 Subject: [PATCH] Update to new doc library Still need to remove deprecated calls --- src/MyWebLog.Data/MyWebLog.Data.fsproj | 4 +- .../Postgres/PostgresCategoryData.fs | 9 ++-- src/MyWebLog.Data/Postgres/PostgresHelpers.fs | 4 +- .../Postgres/PostgresThemeData.fs | 4 +- .../Postgres/PostgresWebLogData.fs | 22 +++++----- src/MyWebLog.Data/PostgresData.fs | 43 ++++++++++--------- .../SQLite/SQLiteCategoryData.fs | 1 + src/MyWebLog.Data/SQLite/SQLiteHelpers.fs | 9 ++-- src/MyWebLog.Data/SQLite/SQLitePageData.fs | 4 +- src/MyWebLog.Data/SQLite/SQLitePostData.fs | 3 +- src/MyWebLog.Data/SQLite/SQLiteTagMapData.fs | 1 + src/MyWebLog.Data/SQLite/SQLiteThemeData.fs | 10 ++--- src/MyWebLog.Data/SQLite/SQLiteWebLogData.fs | 1 + .../SQLite/SQLiteWebLogUserData.fs | 1 + src/MyWebLog.Data/SQLiteData.fs | 30 ++++++++----- 15 files changed, 83 insertions(+), 63 deletions(-) diff --git a/src/MyWebLog.Data/MyWebLog.Data.fsproj b/src/MyWebLog.Data/MyWebLog.Data.fsproj index 6a5985b..cb6c042 100644 --- a/src/MyWebLog.Data/MyWebLog.Data.fsproj +++ b/src/MyWebLog.Data/MyWebLog.Data.fsproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/MyWebLog.Data/Postgres/PostgresCategoryData.fs b/src/MyWebLog.Data/Postgres/PostgresCategoryData.fs index 6909684..837f810 100644 --- a/src/MyWebLog.Data/Postgres/PostgresCategoryData.fs +++ b/src/MyWebLog.Data/Postgres/PostgresCategoryData.fs @@ -2,6 +2,7 @@ open BitBadger.Documents open BitBadger.Documents.Postgres +open BitBadger.Documents.Postgres.Compat open Microsoft.Extensions.Logging open MyWebLog open MyWebLog.Data @@ -19,7 +20,7 @@ type PostgresCategoryData(log: ILogger) = let countTopLevel webLogId = log.LogTrace "Category.countTopLevel" Custom.scalar - $"""{Query.Count.byContains Table.Category} + $"""{Query.byContains (Query.count Table.Category)} AND {Query.whereByField (Field.NEX (nameof Category.Empty.ParentId)) ""}""" [ webLogContains webLogId ] toCount @@ -87,11 +88,11 @@ type PostgresCategoryData(log: ILogger) = if hasChildren then let childQuery, childParams = if cat.ParentId.IsSome then - Query.Patch.byId Table.Category, + Query.byId (Query.patch Table.Category) "", children |> List.map (fun child -> [ idParam child.Id; jsonParam "@data" {| ParentId = cat.ParentId |} ]) else - Query.RemoveFields.byId Table.Category, + Query.byId (Query.removeFields Table.Category) "", children |> List.map (fun child -> [ idParam child.Id; fieldNameParam [ nameof Category.Empty.ParentId ] ]) @@ -111,7 +112,7 @@ type PostgresCategoryData(log: ILogger) = Configuration.dataSource () |> Sql.fromDataSource |> Sql.executeTransactionAsync - [ Query.Patch.byId Table.Post, + [ Query.byId (Query.patch Table.Post) "", posts |> List.map (fun post -> [ idParam post.Id diff --git a/src/MyWebLog.Data/Postgres/PostgresHelpers.fs b/src/MyWebLog.Data/Postgres/PostgresHelpers.fs index b9e8bff..a37efe1 100644 --- a/src/MyWebLog.Data/Postgres/PostgresHelpers.fs +++ b/src/MyWebLog.Data/Postgres/PostgresHelpers.fs @@ -83,7 +83,7 @@ let webLogContains webLogId = /// A SQL string to select data from a table with the given JSON document contains criteria let selectWithCriteria tableName = - $"""{Query.selectFromTable tableName} WHERE {Query.whereDataContains "@criteria"}""" + $"""{Query.find tableName} WHERE {Query.whereDataContains "@criteria"}""" /// Create the SQL and parameters for an IN clause let inClause<'T> colNameAndPrefix paramName (items: 'T list) = @@ -162,7 +162,7 @@ module Document = /// Find a document by its ID for the given web log let findByIdAndWebLog<'TKey, 'TDoc> table (key: 'TKey) webLogId = Custom.single - $"""{Query.selectFromTable table} WHERE {Query.whereById "@id"} AND {Query.whereDataContains "@criteria"}""" + $"""{Query.find table} WHERE {Query.whereById "@id"} AND {Query.whereDataContains "@criteria"}""" [ "@id", Sql.string (string key); webLogContains webLogId ] fromData<'TDoc> diff --git a/src/MyWebLog.Data/Postgres/PostgresThemeData.fs b/src/MyWebLog.Data/Postgres/PostgresThemeData.fs index 1f4d089..cb953bc 100644 --- a/src/MyWebLog.Data/Postgres/PostgresThemeData.fs +++ b/src/MyWebLog.Data/Postgres/PostgresThemeData.fs @@ -18,7 +18,7 @@ type PostgresThemeData(log: ILogger) = let all () = log.LogTrace "Theme.all" Custom.list - $"{Query.selectFromTable Table.Theme} + $"{Query.find Table.Theme} WHERE data ->> '{nameof Theme.Empty.Id}' <> 'admin' ORDER BY data ->> '{nameof Theme.Empty.Id}'" [] @@ -37,7 +37,7 @@ type PostgresThemeData(log: ILogger) = /// Find a theme by its ID (excludes the text of templates) let findByIdWithoutText (themeId: ThemeId) = log.LogTrace "Theme.findByIdWithoutText" - Custom.single (Query.Find.byId Table.Theme) [ idParam themeId ] withoutTemplateText + Custom.single (Query.byId (Query.find Table.Theme) (string themeId)) [ idParam themeId ] withoutTemplateText /// Delete a theme by its ID let delete themeId = backgroundTask { diff --git a/src/MyWebLog.Data/Postgres/PostgresWebLogData.fs b/src/MyWebLog.Data/Postgres/PostgresWebLogData.fs index 5ec39d4..0d7835e 100644 --- a/src/MyWebLog.Data/Postgres/PostgresWebLogData.fs +++ b/src/MyWebLog.Data/Postgres/PostgresWebLogData.fs @@ -24,21 +24,21 @@ type PostgresWebLogData(log: ILogger) = log.LogTrace "WebLog.delete" Custom.nonQuery $"""DELETE FROM {Table.PostComment} - WHERE data ->> '{nameof Comment.Empty.PostId}' - IN (SELECT data ->> '{nameof Post.Empty.Id}' + WHERE data->>'{nameof Comment.Empty.PostId}' + IN (SELECT data->>'{nameof Post.Empty.Id}' FROM {Table.Post} WHERE {Query.whereDataContains "@criteria"}); DELETE FROM {Table.PostRevision} - WHERE post_id IN (SELECT data ->> 'Id' FROM {Table.Post} WHERE {Query.whereDataContains "@criteria"}); + WHERE post_id IN (SELECT data->>'Id' FROM {Table.Post} WHERE {Query.whereDataContains "@criteria"}); DELETE FROM {Table.PageRevision} - WHERE page_id IN (SELECT data ->> 'Id' FROM {Table.Page} WHERE {Query.whereDataContains "@criteria"}); - {Query.Delete.byContains Table.Post}; - {Query.Delete.byContains Table.Page}; - {Query.Delete.byContains Table.Category}; - {Query.Delete.byContains Table.TagMap}; - {Query.Delete.byContains Table.WebLogUser}; - DELETE FROM {Table.Upload} WHERE web_log_id = @webLogId; - DELETE FROM {Table.WebLog} WHERE {Query.whereById "@webLogId"}""" + WHERE page_id IN (SELECT data->>'Id' FROM {Table.Page} WHERE {Query.whereDataContains "@criteria"}); + {Query.byContains (Query.delete Table.Post)}; + {Query.byContains (Query.delete Table.Page)}; + {Query.byContains (Query.delete Table.Category)}; + {Query.byContains (Query.delete Table.TagMap)}; + {Query.byContains (Query.delete Table.WebLogUser)}; + DELETE FROM {Table.Upload} WHERE web_log_id = @webLogId; + DELETE FROM {Table.WebLog} WHERE data->>'Id' = @webLogId""" [ webLogIdParam webLogId; webLogContains webLogId ] /// Find a web log by its host (URL base) diff --git a/src/MyWebLog.Data/PostgresData.fs b/src/MyWebLog.Data/PostgresData.fs index 0100983..0bc1bd8 100644 --- a/src/MyWebLog.Data/PostgresData.fs +++ b/src/MyWebLog.Data/PostgresData.fs @@ -25,7 +25,7 @@ type PostgresData(log: ILogger, ser: JsonSerializer) = // Theme tables if needsTable Table.Theme then Query.Definition.ensureTable Table.Theme - Query.Definition.ensureKey Table.Theme + Query.Definition.ensureKey Table.Theme PostgreSQL if needsTable Table.ThemeAsset then $"CREATE TABLE {Table.ThemeAsset} ( theme_id TEXT NOT NULL, @@ -37,28 +37,28 @@ type PostgresData(log: ILogger, ser: JsonSerializer) = // Web log table if needsTable Table.WebLog then Query.Definition.ensureTable Table.WebLog - Query.Definition.ensureKey Table.WebLog + Query.Definition.ensureKey Table.WebLog PostgreSQL Query.Definition.ensureDocumentIndex Table.WebLog Optimized // Category table if needsTable Table.Category then Query.Definition.ensureTable Table.Category - Query.Definition.ensureKey Table.Category + Query.Definition.ensureKey Table.Category PostgreSQL Query.Definition.ensureDocumentIndex Table.Category Optimized // Web log user table if needsTable Table.WebLogUser then Query.Definition.ensureTable Table.WebLogUser - Query.Definition.ensureKey Table.WebLogUser + Query.Definition.ensureKey Table.WebLogUser PostgreSQL Query.Definition.ensureDocumentIndex Table.WebLogUser Optimized // Page tables if needsTable Table.Page then Query.Definition.ensureTable Table.Page - Query.Definition.ensureKey Table.Page - Query.Definition.ensureIndexOn Table.Page "author" [ nameof Page.Empty.AuthorId ] + Query.Definition.ensureKey Table.Page PostgreSQL + Query.Definition.ensureIndexOn Table.Page "author" [ nameof Page.Empty.AuthorId ] PostgreSQL Query.Definition.ensureIndexOn - Table.Page "permalink" [ nameof Page.Empty.WebLogId; nameof Page.Empty.Permalink ] + Table.Page "permalink" [ nameof Page.Empty.WebLogId; nameof Page.Empty.Permalink ] PostgreSQL if needsTable Table.PageRevision then $"CREATE TABLE {Table.PageRevision} ( page_id TEXT NOT NULL, @@ -69,14 +69,15 @@ type PostgresData(log: ILogger, ser: JsonSerializer) = // Post tables if needsTable Table.Post then Query.Definition.ensureTable Table.Post - Query.Definition.ensureKey Table.Post - Query.Definition.ensureIndexOn Table.Post "author" [ nameof Post.Empty.AuthorId ] + Query.Definition.ensureKey Table.Post PostgreSQL + Query.Definition.ensureIndexOn Table.Post "author" [ nameof Post.Empty.AuthorId ] PostgreSQL Query.Definition.ensureIndexOn - Table.Post "permalink" [ nameof Post.Empty.WebLogId; nameof Post.Empty.Permalink ] + Table.Post "permalink" [ nameof Post.Empty.WebLogId; nameof Post.Empty.Permalink ] PostgreSQL Query.Definition.ensureIndexOn Table.Post "status" [ nameof Post.Empty.WebLogId; nameof Post.Empty.Status; nameof Post.Empty.UpdatedOn ] + PostgreSQL $"CREATE INDEX idx_post_category ON {Table.Post} USING GIN ((data['{nameof Post.Empty.CategoryIds}']))" $"CREATE INDEX idx_post_tag ON {Table.Post} USING GIN ((data['{nameof Post.Empty.Tags}']))" if needsTable Table.PostRevision then @@ -87,13 +88,13 @@ type PostgresData(log: ILogger, ser: JsonSerializer) = PRIMARY KEY (post_id, as_of))" if needsTable Table.PostComment then Query.Definition.ensureTable Table.PostComment - Query.Definition.ensureKey Table.PostComment - Query.Definition.ensureIndexOn Table.PostComment "post" [ nameof Comment.Empty.PostId ] + Query.Definition.ensureKey Table.PostComment PostgreSQL + Query.Definition.ensureIndexOn Table.PostComment "post" [ nameof Comment.Empty.PostId ] PostgreSQL // Tag map table if needsTable Table.TagMap then Query.Definition.ensureTable Table.TagMap - Query.Definition.ensureKey Table.TagMap + Query.Definition.ensureKey Table.TagMap PostgreSQL Query.Definition.ensureDocumentIndex Table.TagMap Optimized // Uploaded file table @@ -153,7 +154,8 @@ type PostgresData(log: ILogger, ser: JsonSerializer) = Table.WebLogUser ] Utils.Migration.logStep log migration "Adding unique indexes on ID fields" - do! Custom.nonQuery (tables |> List.map Query.Definition.ensureKey |> String.concat "; ") [] + do! Custom.nonQuery + (tables |> List.map (fun it -> Query.Definition.ensureKey it PostgreSQL) |> String.concat "; ") [] Utils.Migration.logStep log migration "Removing constraints" let fkToDrop = @@ -187,24 +189,25 @@ type PostgresData(log: ILogger, ser: JsonSerializer) = Utils.Migration.logStep log migration "Adding new indexes" let newIdx = - [ yield! tables |> List.map Query.Definition.ensureKey + [ yield! tables |> List.map (fun it -> Query.Definition.ensureKey it PostgreSQL) Query.Definition.ensureDocumentIndex Table.Category Optimized Query.Definition.ensureDocumentIndex Table.TagMap Optimized Query.Definition.ensureDocumentIndex Table.WebLog Optimized Query.Definition.ensureDocumentIndex Table.WebLogUser Optimized - Query.Definition.ensureIndexOn Table.Page "author" [ nameof Page.Empty.AuthorId ] + Query.Definition.ensureIndexOn Table.Page "author" [ nameof Page.Empty.AuthorId ] PostgreSQL Query.Definition.ensureIndexOn - Table.Page "permalink" [ nameof Page.Empty.WebLogId; nameof Page.Empty.Permalink ] - Query.Definition.ensureIndexOn Table.Post "author" [ nameof Post.Empty.AuthorId ] + Table.Page "permalink" [ nameof Page.Empty.WebLogId; nameof Page.Empty.Permalink ] PostgreSQL + Query.Definition.ensureIndexOn Table.Post "author" [ nameof Post.Empty.AuthorId ] PostgreSQL Query.Definition.ensureIndexOn - Table.Post "permalink" [ nameof Post.Empty.WebLogId; nameof Post.Empty.Permalink ] + Table.Post "permalink" [ nameof Post.Empty.WebLogId; nameof Post.Empty.Permalink ] PostgreSQL Query.Definition.ensureIndexOn Table.Post "status" [ nameof Post.Empty.WebLogId; nameof Post.Empty.Status; nameof Post.Empty.UpdatedOn ] + PostgreSQL $"CREATE INDEX idx_post_category ON {Table.Post} USING GIN ((data['{nameof Post.Empty.CategoryIds}']))" $"CREATE INDEX idx_post_tag ON {Table.Post} USING GIN ((data['{nameof Post.Empty.Tags}']))" - Query.Definition.ensureIndexOn Table.PostComment "post" [ nameof Comment.Empty.PostId ] ] + Query.Definition.ensureIndexOn Table.PostComment "post" [ nameof Comment.Empty.PostId ] PostgreSQL ] do! Custom.nonQuery (newIdx |> String.concat "; ") [] Utils.Migration.logStep log migration "Setting database to version 2.1.1" diff --git a/src/MyWebLog.Data/SQLite/SQLiteCategoryData.fs b/src/MyWebLog.Data/SQLite/SQLiteCategoryData.fs index 4cf6104..2bd61bf 100644 --- a/src/MyWebLog.Data/SQLite/SQLiteCategoryData.fs +++ b/src/MyWebLog.Data/SQLite/SQLiteCategoryData.fs @@ -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 diff --git a/src/MyWebLog.Data/SQLite/SQLiteHelpers.fs b/src/MyWebLog.Data/SQLite/SQLiteHelpers.fs index bfb8952..0ee1c89 100644 --- a/src/MyWebLog.Data/SQLite/SQLiteHelpers.fs +++ b/src/MyWebLog.Data/SQLite/SQLiteHelpers.fs @@ -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 diff --git a/src/MyWebLog.Data/SQLite/SQLitePageData.fs b/src/MyWebLog.Data/SQLite/SQLitePageData.fs index 17af376..d51d0a1 100644 --- a/src/MyWebLog.Data/SQLite/SQLitePageData.fs +++ b/src/MyWebLog.Data/SQLite/SQLitePageData.fs @@ -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 diff --git a/src/MyWebLog.Data/SQLite/SQLitePostData.fs b/src/MyWebLog.Data/SQLite/SQLitePostData.fs index cc2063e..bae81ff 100644 --- a/src/MyWebLog.Data/SQLite/SQLitePostData.fs +++ b/src/MyWebLog.Data/SQLite/SQLitePostData.fs @@ -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 diff --git a/src/MyWebLog.Data/SQLite/SQLiteTagMapData.fs b/src/MyWebLog.Data/SQLite/SQLiteTagMapData.fs index f71c61e..1c621ee 100644 --- a/src/MyWebLog.Data/SQLite/SQLiteTagMapData.fs +++ b/src/MyWebLog.Data/SQLite/SQLiteTagMapData.fs @@ -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 diff --git a/src/MyWebLog.Data/SQLite/SQLiteThemeData.fs b/src/MyWebLog.Data/SQLite/SQLiteThemeData.fs index 7ff48f3..0717dac 100644 --- a/src/MyWebLog.Data/SQLite/SQLiteThemeData.fs +++ b/src/MyWebLog.Data/SQLite/SQLiteThemeData.fs @@ -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 diff --git a/src/MyWebLog.Data/SQLite/SQLiteWebLogData.fs b/src/MyWebLog.Data/SQLite/SQLiteWebLogData.fs index 4c5a797..cb97c8b 100644 --- a/src/MyWebLog.Data/SQLite/SQLiteWebLogData.fs +++ b/src/MyWebLog.Data/SQLite/SQLiteWebLogData.fs @@ -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 diff --git a/src/MyWebLog.Data/SQLite/SQLiteWebLogUserData.fs b/src/MyWebLog.Data/SQLite/SQLiteWebLogUserData.fs index 35a9cd5..68702d3 100644 --- a/src/MyWebLog.Data/SQLite/SQLiteWebLogUserData.fs +++ b/src/MyWebLog.Data/SQLite/SQLiteWebLogUserData.fs @@ -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 diff --git a/src/MyWebLog.Data/SQLiteData.fs b/src/MyWebLog.Data/SQLiteData.fs index d926894..158ed7c 100644 --- a/src/MyWebLog.Data/SQLiteData.fs +++ b/src/MyWebLog.Data/SQLiteData.fs @@ -25,7 +25,7 @@ type SQLiteData(conn: SqliteConnection, log: ILogger, ser: JsonSeria not (List.contains table tables) let jsonTable table = - $"{Query.Definition.ensureTable table}; {Query.Definition.ensureKey table}" + $"{Query.Definition.ensureTable table}; {Query.Definition.ensureKey table SQLite}" let tasks = seq { @@ -45,7 +45,8 @@ type SQLiteData(conn: SqliteConnection, log: ILogger, ser: JsonSeria // Category table if needsTable Table.Category then $"""{jsonTable Table.Category}; - {Query.Definition.ensureIndexOn Table.Category "web_log" [ nameof Category.Empty.WebLogId ]}""" + {Query.Definition.ensureIndexOn + Table.Category "web_log" [ nameof Category.Empty.WebLogId ] SQLite}""" // Web log user table if needsTable Table.WebLogUser then @@ -53,14 +54,18 @@ type SQLiteData(conn: SqliteConnection, log: ILogger, ser: JsonSeria {Query.Definition.ensureIndexOn Table.WebLogUser "email" - [ nameof WebLogUser.Empty.WebLogId; nameof WebLogUser.Empty.Email ]}""" + [ nameof WebLogUser.Empty.WebLogId; nameof WebLogUser.Empty.Email ] + SQLite}""" // Page tables if needsTable Table.Page then $"""{jsonTable Table.Page}; - {Query.Definition.ensureIndexOn Table.Page "author" [ nameof Page.Empty.AuthorId ]}; + {Query.Definition.ensureIndexOn Table.Page "author" [ nameof Page.Empty.AuthorId ] SQLite}; {Query.Definition.ensureIndexOn - Table.Page "permalink" [ nameof Page.Empty.WebLogId; nameof Page.Empty.Permalink ]}""" + Table.Page + "permalink" + [ nameof Page.Empty.WebLogId; nameof Page.Empty.Permalink ] + SQLite}""" if needsTable Table.PageRevision then $"CREATE TABLE {Table.PageRevision} ( page_id TEXT NOT NULL, @@ -71,13 +76,14 @@ type SQLiteData(conn: SqliteConnection, log: ILogger, ser: JsonSeria // Post tables if needsTable Table.Post then $"""{jsonTable Table.Post}; - {Query.Definition.ensureIndexOn Table.Post "author" [ nameof Post.Empty.AuthorId ]}; + {Query.Definition.ensureIndexOn Table.Post "author" [ nameof Post.Empty.AuthorId ] SQLite}; {Query.Definition.ensureIndexOn - Table.Post "permalink" [ nameof Post.Empty.WebLogId; nameof Post.Empty.Permalink ]}; + Table.Post "permalink" [ nameof Post.Empty.WebLogId; nameof Post.Empty.Permalink ] SQLite}; {Query.Definition.ensureIndexOn Table.Post "status" - [ nameof Post.Empty.WebLogId; nameof Post.Empty.Status; nameof Post.Empty.UpdatedOn ]}""" + [ nameof Post.Empty.WebLogId; nameof Post.Empty.Status; nameof Post.Empty.UpdatedOn ] + SQLite}""" // TODO: index categories by post? if needsTable Table.PostRevision then $"CREATE TABLE {Table.PostRevision} ( @@ -87,13 +93,17 @@ type SQLiteData(conn: SqliteConnection, log: ILogger, ser: JsonSeria PRIMARY KEY (post_id, as_of))" if needsTable Table.PostComment then $"""{jsonTable Table.PostComment}; - {Query.Definition.ensureIndexOn Table.PostComment "post" [ nameof Comment.Empty.PostId ]}""" + {Query.Definition.ensureIndexOn + Table.PostComment "post" [ nameof Comment.Empty.PostId ] SQLite}""" // Tag map table if needsTable Table.TagMap then $"""{jsonTable Table.TagMap}; {Query.Definition.ensureIndexOn - Table.TagMap "url" [ nameof TagMap.Empty.WebLogId; nameof TagMap.Empty.UrlValue ]}""" + Table.TagMap + "url" + [ nameof TagMap.Empty.WebLogId; nameof TagMap.Empty.UrlValue ] + SQLite}""" // Uploaded file table if needsTable Table.Upload then