File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
src/Database/PostgreSQL/Protocol Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,16 @@ library
21
21
, Database.PostgreSQL.Protocol.Connection
22
22
, Database.PostgreSQL.Protocol.Encoders
23
23
, Database.PostgreSQL.Protocol.Decoders
24
+ , Database.PostgreSQL.Protocol.StatementStorage
24
25
build-depends : base >= 4.7 && < 5
25
26
, bytestring
26
27
, socket
27
28
, socket-unix
28
29
, vector
29
30
, binary
30
31
, time
32
+ , hashable
33
+ , hashtables
31
34
default-language : Haskell2010
32
35
default-extensions : OverloadedStrings
33
36
Original file line number Diff line number Diff line change
1
+ module Database.PostgreSQL.Protocol.StatementStorage where
2
+
3
+ import qualified Data.HashTable.IO as H
4
+ import qualified Data.ByteString as B
5
+ import Data.ByteString.Char8 (pack )
6
+ import Data.Word (Word )
7
+ import Data.IORef
8
+
9
+ import Database.PostgreSQL.Protocol.Types
10
+
11
+ -- | Prepared statement storage
12
+ data StatementStorage = StatementStorage
13
+ (H. CuckooHashTable StatementSQL StatementName ) (IORef Word )
14
+
15
+ newStatementStorage :: IO StatementStorage
16
+ newStatementStorage = StatementStorage <$> H. new <*> newIORef 0
17
+
18
+ lookupStatement :: StatementStorage -> StatementSQL -> IO (Maybe StatementName )
19
+ lookupStatement (StatementStorage table _) = H. lookup table
20
+
21
+ storageStatement :: StatementStorage -> StatementSQL -> IO StatementName
22
+ storageStatement (StatementStorage table counter) stmt = do
23
+ n <- readIORef counter
24
+ writeIORef counter $ n + 1
25
+ let name = pack $ show n
26
+ H. insert table name stmt
27
+ pure name
28
+
You can’t perform that action at this time.
0 commit comments