Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.

Version 2 #5

Merged
merged 7 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
dotnet-version: [ "6.0", "7.0" ]
dotnet-version: [ "6.0", "7.0", "8.0" ]
postgres-version: [ "12", "13", "14", "15", "latest" ]

services:
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0"
dotnet-version: "8.0"
- name: Package F# Library
run: dotnet pack src/$FS_PROJECT/$FS_PROJECT.fsproj -c Release
- name: Move F# package
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,6 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
.vscode/

# JetBrains
.idea/
344 changes: 165 additions & 179 deletions src/BitBadger.Npgsql.Documents.Tests/CSharpTests.fs

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/BitBadger.Npgsql.Documents.Tests/Db.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,26 @@ let connStr =

/// Create a data source using the derived connection string
let mkDataSource cStr =
(NpgsqlDataSourceBuilder cStr).Build ()
NpgsqlDataSourceBuilder(cStr).Build()


open BitBadger.Npgsql.FSharp.Documents

/// Build the throwaway database
let buildDatabase () =

let database = ThrowawayDatabase.Create(connStr)
let database = ThrowawayDatabase.Create connStr

database.ConnectionString
|> Sql.connect
let sqlProps = Sql.connect database.ConnectionString

sqlProps
|> Sql.query (Definition.createTable tableName)
|> Sql.executeNonQuery
|> ignore
sqlProps
|> Sql.query (Definition.createKey tableName)
|> Sql.executeNonQuery
|> ignore

Configuration.useDataSource (mkDataSource database.ConnectionString)

Expand Down
170 changes: 77 additions & 93 deletions src/BitBadger.Npgsql.Documents.Tests/FSharpTests.fs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/BitBadger.Npgsql.Documents.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "BitBadger.Npgsql.Documents.
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "BitBadger.Npgsql.Documents", "BitBadger.Npgsql.Documents\BitBadger.Npgsql.Documents.fsproj", "{D6FEDBB8-D20D-4D14-AEC8-5CA2EA32EDB0}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MigrateToV2", "MigrateToV2\MigrateToV2.fsproj", "{B288C600-8081-496E-8A92-DB861273779E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,5 +32,9 @@ Global
{D6FEDBB8-D20D-4D14-AEC8-5CA2EA32EDB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6FEDBB8-D20D-4D14-AEC8-5CA2EA32EDB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6FEDBB8-D20D-4D14-AEC8-5CA2EA32EDB0}.Release|Any CPU.Build.0 = Release|Any CPU
{B288C600-8081-496E-8A92-DB861273779E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B288C600-8081-496E-8A92-DB861273779E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B288C600-8081-496E-8A92-DB861273779E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B288C600-8081-496E-8A92-DB861273779E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
16 changes: 12 additions & 4 deletions src/BitBadger.Npgsql.Documents/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@ open Npgsql
open BitBadger.Npgsql.FSharp.Documents

/// Specify the serializer to use for document serialization/deserialization
let UseSerializer (ser : IDocumentSerializer) =
let UseSerializer(ser: IDocumentSerializer) =
Configuration.useSerializer ser

/// Retrieve the currently configured serializer
let Serializer () =
let Serializer() =
Configuration.serializer ()

/// Register a data source to use for query execution (disposes the current one if it exists)
let UseDataSource (source : NpgsqlDataSource) =
let UseDataSource(source: NpgsqlDataSource) =
Configuration.useDataSource source

/// Retrieve the currently configured data source
let DataSource () =
let DataSource() =
Configuration.dataSource ()

/// Set the ID field name to use for documents
let UseIdField(name: string) =
Configuration.useIdField name

/// Retrieve the currently configured ID field name
let IdField() =
Configuration.idField ()
20 changes: 11 additions & 9 deletions src/BitBadger.Npgsql.Documents/Definition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module BitBadger.Npgsql.Documents.Definition

open Npgsql.FSharp

/// Alias for F# document module
// Alias for F# document module
module FS = BitBadger.Npgsql.FSharp.Documents

/// Convert the C# index type representation to the F# one
Expand All @@ -13,29 +13,31 @@ let private convertIndexType idxType =
| it -> invalidOp $"Index type {it} invalid"

/// SQL statement to create a document table
let CreateTable (name : string) =
let CreateTable(name: string) =
FS.Definition.createTable name

/// SQL statement to create a key index for a document table
let CreateKey(name: string) =
FS.Definition.createKey name

/// SQL statement to create an index on documents in the specified table
let CreateIndex (name : string, idxType : DocumentIndex) =
let CreateIndex(name: string, idxType: DocumentIndex) =
FS.Definition.createIndex name (convertIndexType idxType)

/// Definitions that take SqlProps as their last parameter
module WithProps =

/// Create a document table
let EnsureTable (name : string, sqlProps : Sql.SqlProps) =
let EnsureTable(name: string, sqlProps: Sql.SqlProps) =
FS.Definition.WithProps.ensureTable name sqlProps

/// Create an index on documents in the specified table
let EnsureIndex (name : string, idxType : DocumentIndex, sqlProps : Sql.SqlProps) =
let EnsureIndex(name: string, idxType: DocumentIndex, sqlProps: Sql.SqlProps) =
FS.Definition.WithProps.ensureIndex name (convertIndexType idxType) sqlProps

/// Create a document table
let EnsureTable name =
WithProps.EnsureTable (name, FS.fromDataSource ())
WithProps.EnsureTable(name, FS.fromDataSource ())

let EnsureIndex (name, idxType) =
WithProps.EnsureIndex (name, idxType, FS.fromDataSource ())


WithProps.EnsureIndex(name, idxType, FS.fromDataSource ())
Loading