all repos — litestore @ 2f78123709b0151b27276a8997148777061cfce8

A minimalist nosql document store.

litestore.nim

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
import 
  sqlite3, 
  db_sqlite as db, 
  strutils, 
  os,
  oids,
  times,
  json,
  pegs, 
  strtabs,
  base64,
  logging
import
  lib/types,
  lib/utils, 
  lib/core,
  lib/cli,
  lib/server

from asyncdispatch import runForever

{.compile: "vendor/sqlite/libsqlite3.c".}
{.passC: "-DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0".}

when isMainModule:
  # Initialize Datastore
  if not LS.file.fileExists:
    try:
      LS.file.createDatastore()
    except:
      fail(200, "Unable to create datastore '$1'" % [LS.file])
  try:
    LS.store = LS.file.openDatastore()
    if LS.mirror:
      try:
        LS.store.mountDir(LS.directory, LS.reset)
      except:
        echo(getCurrentExceptionMsg())
        fail(202, "Unable to mount directory '$1'" % [LS.directory])
  except:
    fail(201, "Unable to open datastore '$1'" % [LS.file])
  case LS.operation:
    of opImport:
      LS.store.importDir(LS.directory)
    of opExport:
      LS.store.exportDir(LS.directory)
    of opDelete:
      LS.store.deleteDir(LS.directory)
    of opRun:
      LS.serve
      runForever()