mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-07 16:13:07 +00:00
rename to SQLiteBackend
This commit is contained in:
parent
113f59cecc
commit
06cb6fc8b0
@ -15,18 +15,18 @@ export backend, sqlitedsdb
|
|||||||
push: {.upraises: [].}
|
push: {.upraises: [].}
|
||||||
|
|
||||||
type
|
type
|
||||||
SQLiteDatastore* = object
|
SQLiteBackend* = object
|
||||||
db: SQLiteDsDb
|
db: SQLiteDsDb
|
||||||
|
|
||||||
proc path*(self: SQLiteDatastore): string =
|
proc path*(self: SQLiteBackend): string =
|
||||||
self.db.dbPath
|
self.db.dbPath
|
||||||
|
|
||||||
proc readOnly*(self: SQLiteDatastore): bool = self.db.readOnly
|
proc readOnly*(self: SQLiteBackend): bool = self.db.readOnly
|
||||||
|
|
||||||
proc timestamp*(t = epochTime()): int64 =
|
proc timestamp*(t = epochTime()): int64 =
|
||||||
(t * 1_000_000).int64
|
(t * 1_000_000).int64
|
||||||
|
|
||||||
proc has*(self: SQLiteDatastore, key: DbKey): ?!bool =
|
proc has*(self: SQLiteBackend, key: DbKey): ?!bool =
|
||||||
var
|
var
|
||||||
exists = false
|
exists = false
|
||||||
key = $key
|
key = $key
|
||||||
@ -39,10 +39,10 @@ proc has*(self: SQLiteDatastore, key: DbKey): ?!bool =
|
|||||||
|
|
||||||
return success exists
|
return success exists
|
||||||
|
|
||||||
proc delete*(self: SQLiteDatastore, key: DbKey): ?!void =
|
proc delete*(self: SQLiteBackend, key: DbKey): ?!void =
|
||||||
return self.db.deleteStmt.exec(($key))
|
return self.db.deleteStmt.exec(($key))
|
||||||
|
|
||||||
proc delete*(self: SQLiteDatastore, keys: openArray[DbKey]): ?!void =
|
proc delete*(self: SQLiteBackend, keys: openArray[DbKey]): ?!void =
|
||||||
if err =? self.db.beginStmt.exec().errorOption:
|
if err =? self.db.beginStmt.exec().errorOption:
|
||||||
return failure(err)
|
return failure(err)
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ proc delete*(self: SQLiteDatastore, keys: openArray[DbKey]): ?!void =
|
|||||||
|
|
||||||
return success()
|
return success()
|
||||||
|
|
||||||
proc get*(self: SQLiteDatastore, key: DbKey): ?!seq[byte] =
|
proc get*(self: SQLiteBackend, key: DbKey): ?!seq[byte] =
|
||||||
# see comment in ./filesystem_datastore re: finer control of memory
|
# see comment in ./filesystem_datastore re: finer control of memory
|
||||||
# allocation in `proc get`, could apply here as well if bytes were read
|
# allocation in `proc get`, could apply here as well if bytes were read
|
||||||
# incrementally with `sqlite3_blob_read`
|
# incrementally with `sqlite3_blob_read`
|
||||||
@ -78,7 +78,7 @@ proc get*(self: SQLiteDatastore, key: DbKey): ?!seq[byte] =
|
|||||||
|
|
||||||
return success bytes
|
return success bytes
|
||||||
|
|
||||||
proc put*(self: SQLiteDatastore, key: DbKey, data: DbVal): ?!void =
|
proc put*(self: SQLiteBackend, key: DbKey, data: DbVal): ?!void =
|
||||||
when DbVal is seq[byte]:
|
when DbVal is seq[byte]:
|
||||||
return self.db.putStmt.exec((key, data, timestamp()))
|
return self.db.putStmt.exec((key, data, timestamp()))
|
||||||
elif DbVal is DataBuffer:
|
elif DbVal is DataBuffer:
|
||||||
@ -86,7 +86,7 @@ proc put*(self: SQLiteDatastore, key: DbKey, data: DbVal): ?!void =
|
|||||||
else:
|
else:
|
||||||
{.error: "unknown type".}
|
{.error: "unknown type".}
|
||||||
|
|
||||||
proc put*(self: SQLiteDatastore, batch: openArray[DbBatchEntry]): ?!void =
|
proc put*(self: SQLiteBackend, batch: openArray[DbBatchEntry]): ?!void =
|
||||||
if err =? self.db.beginStmt.exec().errorOption:
|
if err =? self.db.beginStmt.exec().errorOption:
|
||||||
return failure err
|
return failure err
|
||||||
|
|
||||||
@ -109,12 +109,12 @@ proc put*(self: SQLiteDatastore, batch: openArray[DbBatchEntry]): ?!void =
|
|||||||
|
|
||||||
return success()
|
return success()
|
||||||
|
|
||||||
proc close*(self: SQLiteDatastore): ?!void =
|
proc close*(self: SQLiteBackend): ?!void =
|
||||||
self.db.close()
|
self.db.close()
|
||||||
|
|
||||||
return success()
|
return success()
|
||||||
|
|
||||||
proc query*(self: SQLiteDatastore,
|
proc query*(self: SQLiteBackend,
|
||||||
query: DbQuery
|
query: DbQuery
|
||||||
): Result[iterator(): ?!DbQueryResponse {.closure.}, ref CatchableError] =
|
): Result[iterator(): ?!DbQueryResponse {.closure.}, ref CatchableError] =
|
||||||
|
|
||||||
@ -208,23 +208,23 @@ proc query*(self: SQLiteDatastore,
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
proc contains*(self: SQLiteDatastore, key: DbKey): bool =
|
proc contains*(self: SQLiteBackend, key: DbKey): bool =
|
||||||
return self.has(key).get()
|
return self.has(key).get()
|
||||||
|
|
||||||
|
|
||||||
proc new*(T: type SQLiteDatastore,
|
proc new*(T: type SQLiteBackend,
|
||||||
path: string,
|
path: string,
|
||||||
readOnly = false): ?!SQLiteDatastore =
|
readOnly = false): ?!SQLiteBackend =
|
||||||
|
|
||||||
let
|
let
|
||||||
flags =
|
flags =
|
||||||
if readOnly: SQLITE_OPEN_READONLY
|
if readOnly: SQLITE_OPEN_READONLY
|
||||||
else: SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE
|
else: SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE
|
||||||
|
|
||||||
success SQLiteDatastore(db: ? SQLiteDsDb.open(path, flags))
|
success SQLiteBackend(db: ? SQLiteDsDb.open(path, flags))
|
||||||
|
|
||||||
|
|
||||||
proc new*(T: type SQLiteDatastore,
|
proc new*(T: type SQLiteBackend,
|
||||||
db: SQLiteDsDb): ?!T =
|
db: SQLiteDsDb): ?!T =
|
||||||
|
|
||||||
success SQLiteDatastore(db: db)
|
success SQLiteBackend(db: db)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user