all repos — litestore @ 2a0224257d27d3484ffa7b7669886aa8f47f6c50

A minimalist nosql document store.

Added foreign keys for tags.
h3rald h3rald@h3rald.com
Sat, 23 May 2015 09:54:10 +0200
commit

2a0224257d27d3484ffa7b7669886aa8f47f6c50

parent

ef09525a3dbab75df55c8f2761861b67576edca5

2 files changed, 6 insertions(+), 5 deletions(-)

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

@@ -74,6 +74,7 @@ LOG.debug("Executing PRAGMAs...")

discard result.db.tryExec("PRAGMA locking_mode = exclusive".sql) discard result.db.tryExec("PRAGMA page_size = 4096".sql) discard result.db.tryExec("PRAGMA cache_size = 10000".sql) + discard result.db.tryExec("PRAGMA foreign_keys = ON".sql) LOG.debug("Done.") result.path = file result.mount = ""

@@ -243,7 +244,6 @@ result = store.db.execAffectedRows(SQL_DELETE_DOCUMENT, id)

if result > 0: store.db.exec(SQL_DECREMENT_DOCS) store.db.exec(SQL_DELETE_SEARCHCONTENT, id) - store.db.exec(SQL_DELETE_DOCUMENT_TAGS, id) if store.hasMirror and id.startsWith(store.mount): var filename = id.unixToNativePath if fileExists(filename):
M lib/queries.nimlib/queries.nim

@@ -6,7 +6,7 @@

const SQL_CREATE_DOCUMENTS_TABLE* = sql""" CREATE TABLE documents ( docid INTEGER PRIMARY KEY, -id TEST, +id TEXT UNIQUE NOT NULL, data TEXT, content_type TEXT, binary INTEGER,

@@ -33,15 +33,16 @@ SQL_VACUUM* = sql"VACUUM"

const SQL_CREATE_SEARCHDATA_TABLE* = sql""" CREATE VIRTUAL TABLE searchdata USING fts4( -id TEXT, +id TEXT UNIQUE NOT NULL, data TEXT, tokenize=porter) """ const SQL_CREATE_TAGS_TABLE* = sql""" CREATE TABLE tags ( -tag_id TEXT, -document_id TEXT, +tag_id TEXT NOT NULL, +document_id TEXT NOT NULL, +FOREIGN KEY(document_id) REFERENCES documents(id) ON DELETE CASCADE, PRIMARY KEY (tag_id, document_id)) """