all repos — litestore @ 287e2fa9d69c38fd199a6159784021190c6c0177

A minimalist nosql document store.

Minor changes
Fabio Cevasco h3rald@h3rald.com
Thu, 19 Feb 2015 17:15:40 +0100
commit

287e2fa9d69c38fd199a6159784021190c6c0177

parent

11857fa6dc029cf109fc1d4596ff8ce9b22c3a9a

1 files changed, 12 insertions(+), 10 deletions(-)

jump to
M lib/core.nimlib/core.nim

@@ -18,18 +18,26 @@

# Manage Datastores proc createDatastore*(file:string) = - if file.fileExists: + if file.fileExists(): raise newException(EDatastoreExists, "Datastore '$1' already exists." % file) let store = db.open(file, "", "", "") store.exec(SQL_CREATE_DOCUMENTS_TABLE) store.exec(SQL_CREATE_SEARCHCONTENTS_TABLE) store.exec(SQL_CREATE_TAGS_TABLE) -proc destroyDatastore*(file:string) = +proc closeDatastore*(store:Datastore) = try: - file.removeFile + db.close(store.db) except: - raise newException(EDatastoreUnavailable, "Datastore '$1' cannot destroyd." % file) + raise newException(EDatastoreUnavailable, "Datastore '$1' cannot be closed." % store.path) + +proc destroyDatastore*(store:Datastore) = + try: + if store.path.fileExists(): + store.closeDataStore() + store.path.removeFile() + except: + raise newException(EDatastoreUnavailable, "Datastore '$1' cannot destroyed." % store.path) proc openDatastore*(file:string): Datastore = if not file.fileExists:

@@ -39,12 +47,6 @@ result.db = db.open(file, "", "", "")

result.path = file except: raise newException(EDatastoreUnavailable, "Datastore '$1' cannot be opened." % file) - -proc closeDatastore*(store:Datastore) = - try: - db.close(store.db) - except: - raise newException(EDatastoreUnavailable, "Datastore '$1' cannot be closed." % store.path) # Manage Documents