Combined all F# code into one project
Less to migrate, less to maintain, and I'll never swap these out as components; might as well get the ease of managing them all in one project.
This commit is contained in:
39
src/MyWebLog.App/Data/WebLog.fs
Normal file
39
src/MyWebLog.App/Data/WebLog.fs
Normal file
@@ -0,0 +1,39 @@
|
||||
module MyWebLog.Data.RethinkDB.WebLog
|
||||
|
||||
open MyWebLog.Entities
|
||||
open RethinkDb.Driver.Ast
|
||||
|
||||
let private r = RethinkDb.Driver.RethinkDB.R
|
||||
|
||||
/// Detemine the web log by the URL base
|
||||
let tryFindWebLogByUrlBase conn (urlBase : string) =
|
||||
async {
|
||||
let! cursor =
|
||||
r.Table(Table.WebLog)
|
||||
.GetAll(urlBase).OptArg("index", "UrlBase")
|
||||
.Merge(ReqlFunction1 (fun w ->
|
||||
upcast r.HashMap(
|
||||
"PageList", r.Table(Table.Page)
|
||||
.GetAll(w.G("id")).OptArg("index", "WebLogId")
|
||||
.Filter(ReqlFunction1 (fun pg -> upcast pg.["ShowInPageList"].Eq true))
|
||||
.OrderBy("Title")
|
||||
.Pluck("Title", "Permalink")
|
||||
.CoerceTo("array"))))
|
||||
.RunCursorAsync<WebLog> conn
|
||||
return cursor |> Seq.tryHead
|
||||
}
|
||||
|> Async.RunSynchronously
|
||||
|
||||
/// Get counts for the admin dashboard
|
||||
let findDashboardCounts conn (webLogId : string) =
|
||||
async {
|
||||
return!
|
||||
r.Expr(
|
||||
r.HashMap(
|
||||
"Pages", r.Table(Table.Page ).GetAll(webLogId).OptArg("index", "WebLogId").Count()).With(
|
||||
"Posts", r.Table(Table.Post ).GetAll(webLogId).OptArg("index", "WebLogId").Count()).With(
|
||||
"Categories", r.Table(Table.Category).GetAll(webLogId).OptArg("index", "WebLogId").Count()))
|
||||
.RunResultAsync<DashboardCounts> conn
|
||||
}
|
||||
|> Async.RunSynchronously
|
||||
|
||||
Reference in New Issue
Block a user