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