mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-05 07:03:12 +00:00
databuffer type
This commit is contained in:
parent
b388d242bb
commit
29ff227d37
@ -29,11 +29,12 @@ proc timestamp*(t = epochTime()): int64 =
|
||||
proc has*(self: SQLiteDatastore, key: DbKey): ?!bool =
|
||||
var
|
||||
exists = false
|
||||
key = $key
|
||||
|
||||
proc onData(s: RawStmtPtr) =
|
||||
exists = sqlite3_column_int64(s, ContainsStmtExistsCol.cint).bool
|
||||
|
||||
if err =? self.db.containsStmt.query((key.id), onData).errorOption:
|
||||
if err =? self.db.containsStmt.query((key), onData).errorOption:
|
||||
return failure err
|
||||
|
||||
return success exists
|
||||
|
||||
@ -4,13 +4,14 @@ import pkg/questionable
|
||||
import pkg/questionable/results
|
||||
import pkg/upraises
|
||||
|
||||
import ../backend
|
||||
import ./sqliteutils
|
||||
|
||||
export sqliteutils
|
||||
|
||||
type
|
||||
BoundIdCol* = proc (): string {.closure, gcsafe, upraises: [].}
|
||||
BoundDataCol* = proc (): seq[byte] {.closure, gcsafe, upraises: [].}
|
||||
BoundDataCol* = proc (): DataBuffer {.closure, gcsafe, upraises: [].}
|
||||
BoundTimestampCol* = proc (): int64 {.closure, gcsafe, upraises: [].}
|
||||
|
||||
# feels odd to use `void` for prepared statements corresponding to SELECT
|
||||
@ -19,7 +20,7 @@ type
|
||||
ContainsStmt* = SQLiteStmt[(string), void]
|
||||
DeleteStmt* = SQLiteStmt[(string), void]
|
||||
GetStmt* = SQLiteStmt[(string), void]
|
||||
PutStmt* = SQLiteStmt[(string, seq[byte], int64), void]
|
||||
PutStmt* = SQLiteStmt[(string, DataBuffer, int64), void]
|
||||
QueryStmt* = SQLiteStmt[(string), void]
|
||||
BeginStmt* = NoParamsStmt
|
||||
EndStmt* = NoParamsStmt
|
||||
@ -162,7 +163,7 @@ proc dataCol*(
|
||||
|
||||
checkColMetadata(s, index, DataColName)
|
||||
|
||||
return proc (): seq[byte] =
|
||||
return proc (): DataBuffer =
|
||||
let
|
||||
i = index.cint
|
||||
blob = sqlite3_column_blob(s, i)
|
||||
@ -186,7 +187,8 @@ proc dataCol*(
|
||||
dataLen = sqlite3_column_bytes(s, i)
|
||||
dataBytes = cast[ptr UncheckedArray[byte]](blob)
|
||||
|
||||
@(toOpenArray(dataBytes, 0, dataLen - 1))
|
||||
# copy data out, since sqlite will free it
|
||||
DataBuffer.new(toOpenArray(dataBytes, 0, dataLen - 1))
|
||||
|
||||
proc timestampCol*(
|
||||
s: RawStmtPtr,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user