V2 #36
|
@ -88,14 +88,17 @@ type PostgresCategoryData (source : NpgsqlDataSource, log : ILogger) =
|
|||
match! findById catId webLogId with
|
||||
| Some cat ->
|
||||
// Reassign any children to the category's parent category
|
||||
let! children = Find.byContains Table.Category {| ParentId = CategoryId.toString catId |}
|
||||
let! children = Find.byContains<Category> Table.Category {| ParentId = CategoryId.toString catId |}
|
||||
let hasChildren = not (List.isEmpty children)
|
||||
if hasChildren then
|
||||
let! _ =
|
||||
Sql.fromDataSource source
|
||||
|> Sql.executeTransactionAsync [
|
||||
Query.update Table.Category,
|
||||
children |> List.map (fun child -> catParameters { child with ParentId = cat.ParentId })
|
||||
Query.Update.partialById Table.Category,
|
||||
children |> List.map (fun child -> [
|
||||
"@id", Sql.string (CategoryId.toString child.Id)
|
||||
"@data", Query.jsonbDocParam {| ParentId = cat.ParentId |}
|
||||
])
|
||||
]
|
||||
()
|
||||
// Delete the category off all posts where it is assigned
|
||||
|
@ -108,13 +111,11 @@ type PostgresCategoryData (source : NpgsqlDataSource, log : ILogger) =
|
|||
let! _ =
|
||||
Sql.fromDataSource source
|
||||
|> Sql.executeTransactionAsync [
|
||||
Query.update Table.Post,
|
||||
Query.Update.partialById Table.Post,
|
||||
posts |> List.map (fun post -> [
|
||||
"@id", Sql.string (PostId.toString post.Id)
|
||||
"@data", Query.jsonbDocParam
|
||||
{ post with
|
||||
CategoryIds = post.CategoryIds |> List.filter (fun cat -> cat <> catId)
|
||||
}
|
||||
{| CategoryIds = post.CategoryIds |> List.filter (fun cat -> cat <> catId) |}
|
||||
])
|
||||
]
|
||||
()
|
||||
|
|
|
@ -161,11 +161,11 @@ type PostgresPageData (source : NpgsqlDataSource, log : ILogger) =
|
|||
/// Update a page's prior permalinks
|
||||
let updatePriorPermalinks pageId webLogId permalinks = backgroundTask {
|
||||
log.LogTrace "Page.updatePriorPermalinks"
|
||||
match! findById pageId webLogId with
|
||||
| Some page ->
|
||||
do! update Table.Page (PageId.toString page.Id) { page with PriorPermalinks = permalinks }
|
||||
match! pageExists pageId webLogId with
|
||||
| true ->
|
||||
do! Update.partialById Table.Page (PageId.toString pageId) {| PriorPermalinks = permalinks |}
|
||||
return true
|
||||
| None -> return false
|
||||
| false -> return false
|
||||
}
|
||||
|
||||
interface IPageData with
|
||||
|
|
|
@ -3,7 +3,6 @@ namespace MyWebLog.Data.Postgres
|
|||
open Microsoft.Extensions.Logging
|
||||
open MyWebLog
|
||||
open MyWebLog.Data
|
||||
open NodaTime
|
||||
open NodaTime.Text
|
||||
open Npgsql
|
||||
open Npgsql.FSharp
|
||||
|
@ -230,11 +229,11 @@ type PostgresPostData (source : NpgsqlDataSource, log : ILogger) =
|
|||
/// Update prior permalinks for a post
|
||||
let updatePriorPermalinks postId webLogId permalinks = backgroundTask {
|
||||
log.LogTrace "Post.updatePriorPermalinks"
|
||||
match! findById postId webLogId with
|
||||
| Some post ->
|
||||
do! update Table.Post (PostId.toString post.Id) { post with PriorPermalinks = permalinks }
|
||||
match! postExists postId webLogId with
|
||||
| true ->
|
||||
do! Update.partialById Table.Post (PostId.toString postId) {| PriorPermalinks = permalinks |}
|
||||
return true
|
||||
| None -> return false
|
||||
| false -> return false
|
||||
}
|
||||
|
||||
interface IPostData with
|
||||
|
|
|
@ -50,7 +50,7 @@ type PostgresUploadData (source : NpgsqlDataSource, log : ILogger) =
|
|||
if Option.isSome path then
|
||||
let! _ =
|
||||
Sql.fromDataSource source
|
||||
|> Sql.query $"DELETE FROM {Table.Upload} WHERE id = @id"
|
||||
|> Sql.query (Documents.Query.Delete.byId Table.Upload)
|
||||
|> Sql.parameters idParam
|
||||
|> Sql.executeNonQueryAsync
|
||||
return Ok path.Value
|
||||
|
|
|
@ -23,19 +23,19 @@ type PostgresWebLogData (source : NpgsqlDataSource, log : ILogger) =
|
|||
/// Delete a web log by its ID
|
||||
let delete webLogId = backgroundTask {
|
||||
log.LogTrace "WebLog.delete"
|
||||
let criteria = Query.whereDataContains "@criteria"
|
||||
let! _ =
|
||||
Sql.fromDataSource source
|
||||
|> Sql.query $"
|
||||
|> Sql.query $"""
|
||||
DELETE FROM {Table.PostComment}
|
||||
WHERE data->>'{nameof Comment.empty.PostId}' IN (SELECT id FROM {Table.Post} WHERE {criteria});
|
||||
DELETE FROM {Table.Post} WHERE {criteria};
|
||||
DELETE FROM {Table.Page} WHERE {criteria};
|
||||
DELETE FROM {Table.Category} WHERE {criteria};
|
||||
DELETE FROM {Table.TagMap} WHERE {criteria};
|
||||
DELETE FROM {Table.Upload} WHERE web_log_id = @webLogId;
|
||||
DELETE FROM {Table.WebLogUser} WHERE {criteria};
|
||||
DELETE FROM {Table.WebLog} WHERE id = @webLogId"
|
||||
WHERE data ->> '{nameof Comment.empty.PostId}' IN
|
||||
(SELECT id FROM {Table.Post} 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 id = @webLogId"""
|
||||
|> Sql.parameters [ webLogIdParam webLogId; webLogContains webLogId ]
|
||||
|> Sql.executeNonQueryAsync
|
||||
()
|
||||
|
@ -58,13 +58,13 @@ type PostgresWebLogData (source : NpgsqlDataSource, log : ILogger) =
|
|||
/// Update settings for a web log
|
||||
let updateSettings (webLog : WebLog) =
|
||||
log.LogTrace "WebLog.updateSettings"
|
||||
update Table.WebLog (WebLogId.toString webLog.Id) webLog
|
||||
Update.full Table.WebLog (WebLogId.toString webLog.Id) webLog
|
||||
|
||||
/// Update RSS options for a web log
|
||||
let updateRssOptions (webLog : WebLog) = backgroundTask {
|
||||
log.LogTrace "WebLog.updateRssOptions"
|
||||
match! findById webLog.Id with
|
||||
| Some blog -> do! update Table.WebLog (WebLogId.toString webLog.Id) { blog with Rss = webLog.Rss }
|
||||
| Some _ -> do! Update.partialById Table.WebLog (WebLogId.toString webLog.Id) {| Rss = webLog.Rss |}
|
||||
| None -> ()
|
||||
}
|
||||
|
||||
|
|
|
@ -86,10 +86,10 @@ type PostgresWebLogUserData (source : NpgsqlDataSource, log : ILogger) =
|
|||
/// Set a user's last seen date/time to now
|
||||
let setLastSeen userId webLogId = backgroundTask {
|
||||
log.LogTrace "WebLogUser.setLastSeen"
|
||||
match! findById userId webLogId with
|
||||
| Some user ->
|
||||
do! update Table.WebLogUser (WebLogUserId.toString userId) { user with LastSeenOn = Some (Noda.now ()) }
|
||||
| None -> ()
|
||||
match! Document.existsByWebLog source Table.WebLogUser userId WebLogUserId.toString webLogId with
|
||||
| true ->
|
||||
do! Update.partialById Table.WebLogUser (WebLogUserId.toString userId) {| LastSeenOn = Some (Noda.now ()) |}
|
||||
| false -> ()
|
||||
}
|
||||
|
||||
/// Save a user
|
||||
|
|
Loading…
Reference in New Issue
Block a user