Register serliazer for SQLite

This commit is contained in:
Daniel J. Summers 2023-12-31 14:08:41 -05:00
parent 1a50c68668
commit dee2222eb1
3 changed files with 14 additions and 6 deletions

View File

@ -14,11 +14,7 @@ type PostgresData(log: ILogger<PostgresData>, ser: JsonSerializer) =
/// Create any needed tables
let ensureTables () = backgroundTask {
// Set up the PostgreSQL document store
Configuration.useSerializer
{ new IDocumentSerializer with
member _.Serialize<'T>(it: 'T) : string = Utils.serialize ser it
member _.Deserialize<'T>(it: string) : 'T = Utils.deserialize ser it
}
Configuration.useSerializer (Utils.createDocumentSerializer ser)
let! tables =
Custom.list "SELECT tablename FROM pg_tables WHERE schemaname = 'public'" []

View File

@ -16,6 +16,8 @@ type SQLiteData(conn: SqliteConnection, log: ILogger<SQLiteData>, ser: JsonSeria
/// Create tables (and their associated indexes) if they do not exist
let ensureTables () = backgroundTask {
Configuration.useSerializer (Utils.createDocumentSerializer ser)
let! tables = conn.customList<string> "SELECT name FROM sqlite_master WHERE type = 'table'" [] _.GetString(0)
let needsTable table =

View File

@ -50,6 +50,16 @@ let serialize<'T> ser (item: 'T) =
let deserialize<'T> (ser: JsonSerializer) value =
JsonConvert.DeserializeObject<'T>(value, Json.settings ser)
open BitBadger.Documents
/// Create a document serializer using the given JsonSerializer
let createDocumentSerializer ser =
{ new IDocumentSerializer with
member _.Serialize<'T>(it: 'T) : string = serialize ser it
member _.Deserialize<'T>(it: string) : 'T = deserialize ser it
}
open Microsoft.Extensions.Logging
/// Log a migration step