~ehmry/nim-tkrzw

db727b5bb7be41778b1437b9f9a0c3acb0c4a450 — Emery Hemingway 3 years ago 25ffe72 v0.1.1
Export meta types and some standard procs
2 files changed, 32 insertions(+), 12 deletions(-)

M src/tkrzw.nim
M tkrzw.nimble
M src/tkrzw.nim => src/tkrzw.nim +31 -11
@@ 52,9 52,9 @@ type
  CacheDBM* = ref CacheDBMObj
    ## On-memory database manager implementation with LRU deletion.

  FileDBM = HashDBM | TreeDBM | SkipDBM
  MemoryDBM = TinyDBM | BabyDBM | CacheDBM
  DBM = FileDBM | MemoryDBM
  FileDBM* = HashDBM | TreeDBM | SkipDBM
  MemoryDBM* = TinyDBM | BabyDBM | CacheDBM
  DBM* = FileDBM | MemoryDBM

using dbm: DBM



@@ 97,9 97,12 @@ template importDBM(T: untyped): untyped =
  proc MakeIterator(dbm: T): Iterator {.importcpp: "#->MakeIterator()".}
  proc Synchronize(dbm: T; hard: bool): Status {.
      importcpp: "#->Synchronize(@)".}
  proc Count(dbm: T; count: ptr int64): Status {.importcpp: "#->Count(@)".}
  proc GetFileSize(dbm: T; size: ptr int64): Status {.importcpp: "#->GetFileSize(@)".}
  proc Clear(dbm: T): Status {.importcpp: "#->Clear()".}
  proc Rebuild(dbm: T): Status {.importcpp: "#->Rebuild()".}
  proc ShouldBeRebuilt(dbm: T; toBe: ptr bool): Status {.
      importcpp: "#->ShouldBeRebuilt()".}
      importcpp: "#->ShouldBeRebuilt(@)".}
  proc IsOpen(dbm: T): bool {.importcpp: "#->IsOpen()".}
  proc IsWritable(dbm: T): bool {.importcpp: "#->IsWritable()".}
  proc IsHealthy(dbm: T): bool {.importcpp: "#->IsHealthy()".}


@@ 116,12 119,15 @@ proc construct[T](): T =
  new(result)
  {.emit: "new ((void*)result) tkrzw::" & $T & "();".}

proc newDbm*[T: DBM](path: string; rw: RW; options: set[OpenOption] = {}): T =
  var opts: int32
  for o in options.items: opts.inc o.int32
  result = construct[T]()
  result.Open(path, rw == writeable, opts)

template declareNewFile(T: untyped): untyped =
  proc `new T`*(path: string; rw: RW; options: set[OpenOption] = {}): T =
    var opts: int32
    for o in options.items: opts.inc o.int32
    result = construct[T]()
    result.Open(path, rw == writeable, opts)
    newDBM[T](path, rw, options)

template declareNewMem(T: untyped): untyped =
  proc `new T`*(): T = construct[T]()


@@ 177,14 183,28 @@ proc synchronize*(dbm; hard: bool) =
  ## Synchronizes the content of the database to the file system.
  check dbm.Synchronize(hard)

proc shouldBeRebuilt*(dbm): bool =
  ## Checks whether the database should be rebuilt, in a simple way.
  discard dbm.ShouldBeRebuilt(addr result)
proc len*(dbm): int64 =
  ## Gets the number of records.
  var st = dbm.Count(addr result)
  check st

proc fileSize*(dbm): int64 =
  ## Gets the current file size of the database.
  var st = dbm.GetFileSize(addr result)
  check st

proc clear*(dbm) =
  ## Removes all records.
  check dbm.Clear()

proc rebuild*(dbm) =
  ## Rebuilds the entire database.
  check dbm.Rebuild()

proc shouldBeRebuilt*(dbm): bool =
  ## Checks whether the database should be rebuilt, in a simple way.
  check dbm.ShouldBeRebuilt(addr result)

proc rebuild*(dbm: TinyDBM; numBuckets = -1) =
  ## Rebuilds the entire database.
  ## When `numBuckets` is calculated implicitly when -1.

M tkrzw.nimble => tkrzw.nimble +1 -1
@@ 1,6 1,6 @@
# Package

version       = "0.1.0"
version       = "0.1.1"
author        = "Emery Hemingway"
description   = "Wrapper of the Tkrzw key-value database library"
license       = "Apache-2.0"