@@ -7,16 +7,11 @@ type PostgresConfig =
7
7
port: string
8
8
username: string
9
9
password: string
10
- database: string }
11
-
12
- type PoolingConfig =
13
- { minPoolSize: int option
14
- maxPoolSize: int option
15
- connectionIdleLifeTime: int option
16
- connectionPruningInterval: int option }
10
+ database: string
11
+ schema: string option }
17
12
18
13
module Postgres =
19
- let private storeSettings ( config : PostgresConfig ): string =
14
+ let private settingsStringFromConfig ( config : PostgresConfig ): string =
20
15
sprintf
21
16
" Host=%s ;Port=%s ;User Id=%s ;Password=%s ;Database=%s "
22
17
config.host
@@ -25,47 +20,42 @@ module Postgres =
25
20
config.password
26
21
config.database
27
22
28
- let private poolingSettings ( pooling : PoolingConfig ): string =
29
- let minSize =
30
- pooling.minPoolSize |> Option.defaultValue 0
31
-
32
- let maxSize =
33
- pooling.maxPoolSize |> Option.defaultValue 100
34
-
35
- let connectionPruningInterval =
36
- pooling.connectionPruningInterval
37
- |> Option.defaultValue 300
23
+ let private setSchema ( schema : string option )
24
+ ( settings : SqlStreamStore.PostgresStreamStoreSettings )
25
+ : SqlStreamStore.PostgresStreamStoreSettings =
26
+ match schema with
27
+ | None -> ()
28
+ | Some schema -> settings.Schema <- schema
38
29
39
- let connectionIdleLifeTime =
40
- pooling.connectionIdleLifeTime
41
- |> Option.defaultValue 10
42
-
43
- sprintf
44
- " Minimum Pool Size=%d ;Maximum Pool Size=%d ;Connection Idle Lifetime=%d ;Connection Pruning Interval%d "
45
- minSize
46
- maxSize
47
- connectionPruningInterval
48
- connectionIdleLifeTime
30
+ settings
49
31
50
- let private storeSettingsWithPooling ( config : PostgresConfig ) ( pooling : PoolingConfig ): string =
51
- sprintf " %s ;%s " ( storeSettings config) ( poolingSettings pooling)
32
+ /// Connects to a postgres database given a configuration record and an optional schema.
33
+ /// If no schema is provided the tables will be created directly in the public one.
34
+ let connect ( config : PostgresConfig ) ( schema : string option ): SqlStreamStore.PostgresStreamStore =
35
+ let storeSettings =
36
+ SqlStreamStore.PostgresStreamStoreSettings( settingsStringFromConfig config)
37
+ |> setSchema schema
52
38
53
- let createStore ( config : PostgresConfig ): SqlStreamStore.PostgresStreamStore =
54
- new SqlStreamStore.PostgresStreamStore( SqlStreamStore.PostgresStreamStoreSettings( storeSettings config))
39
+ new SqlStreamStore.PostgresStreamStore( storeSettings)
55
40
56
- let createStoreWithPoolingConfig ( config : PostgresConfig ) ( pooling : PoolingConfig ): SqlStreamStore.PostgresStreamStore =
57
- new SqlStreamStore.PostgresStreamStore( SqlStreamStore.PostgresStreamStoreSettings
58
- ( storeSettingsWithPooling config pooling))
41
+ /// Connects to a postgres database given a Npgsql configuration string and an optional schema.
42
+ /// If no schema is provided the tables will be created directly in the public one.
43
+ let createStoreWithConfigString ( config : string ) ( schema : string option ): SqlStreamStore.PostgresStreamStore =
44
+ let storeSettings =
45
+ SqlStreamStore.PostgresStreamStoreSettings( config)
46
+ |> setSchema schema
59
47
60
- let createStoreWithConfigString ( config : string ): SqlStreamStore.PostgresStreamStore =
61
- new SqlStreamStore.PostgresStreamStore( SqlStreamStore.PostgresStreamStoreSettings( config))
48
+ new SqlStreamStore.PostgresStreamStore( storeSettings)
62
49
50
+ /// Creates messages, and streams tables that house the data.
51
+ /// Can throw exceptions.
63
52
let createSchemaRaw ( store : SqlStreamStore.PostgresStreamStore ): Async < unit > =
64
53
async {
65
54
return ! store.CreateSchemaIfNotExists()
66
55
|> Async.awaitTaskWithInnerException'
67
56
}
68
57
69
- let createSchema ( store : SqlStreamStore.PostgresStreamStore ): Async < Result < unit , string >> =
58
+ /// Creates messages, and streams tables that house the data.
59
+ let createSchema ( store : SqlStreamStore.PostgresStreamStore ): Async < Result < unit , exn >> =
70
60
createSchemaRaw store
71
61
|> ExceptionsHandler.asyncExceptionHandler
0 commit comments