Skip to content

Commit

Permalink
feat(alloc): optimize mem allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalie Perret committed Oct 17, 2021
1 parent 873ea0f commit e0bb01c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Vp.FSharp.Sql.Sqlite/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ type SqliteDependencies =
[<AbstractClass; Sealed>]
type internal Constants private () =

static let beginTransactionAsync (connection: SQLiteConnection) (isolationLevel: IsolationLevel) _ =
ValueTask.FromResult(connection.BeginTransaction(isolationLevel))

static let executeReaderAsync (command: SQLiteCommand) _ =
Task.FromResult(command.ExecuteReader())

static let deps : SqliteDependencies =
{ CreateCommand = fun connection -> connection.CreateCommand()
SetCommandTransaction = fun command transaction -> command.Transaction <- transaction
BeginTransaction = fun connection -> connection.BeginTransaction
BeginTransactionAsync = beginTransactionAsync
ExecuteReader = fun command -> command.ExecuteReader()
ExecuteReaderAsync = executeReaderAsync
DbValueToParameter = Constants.DbValueToParameter }

static member DbValueToParameter name value =
let parameter = SQLiteParameter()
parameter.ParameterName <- name
Expand All @@ -71,17 +86,4 @@ type internal Constants private () =

parameter

static member Deps : SqliteDependencies =
let beginTransactionAsync (connection: SQLiteConnection) (isolationLevel: IsolationLevel) _ =
ValueTask.FromResult(connection.BeginTransaction(isolationLevel))

let executeReaderAsync (command: SQLiteCommand) _ =
Task.FromResult(command.ExecuteReader())

{ CreateCommand = fun connection -> connection.CreateCommand()
SetCommandTransaction = fun command transaction -> command.Transaction <- transaction
BeginTransaction = fun connection -> connection.BeginTransaction
BeginTransactionAsync = beginTransactionAsync
ExecuteReader = fun command -> command.ExecuteReader()
ExecuteReaderAsync = executeReaderAsync
DbValueToParameter = Constants.DbValueToParameter }
static member Deps = deps

0 comments on commit e0bb01c

Please sign in to comment.