Permalink
Browse files

Load schema for gallery DB; reorg db-spec creation

  • Loading branch information...
1 parent c6df0ed commit e89807bd0d9f5050471ee626f89716be9ef77822 @timmc committed Mar 4, 2012
Showing with 60 additions and 10 deletions.
  1. +15 −8 clj/src/kpawebgen/config.clj
  2. +43 −0 clj/src/kpawebgen/gallery.sql
  3. +2 −2 clj/src/kpawebgen/slurp.clj
@@ -7,12 +7,19 @@
[conf]
(.getCanonicalFile (.getParentFile (u/file (:_config_path conf)))))
-(defn db-spec
- "Get a DB spec from a config map."
+(defn shadow-db-file
+ "Get the shadow DB File from a config map."
[conf]
- (let [path (u/file (config-dir conf)
- (:kpa_dir conf)
- (:shadow_path conf))]
- {:classname "org.sqlite.JDBC"
- :subprotocol "sqlite"
- :subname (.getCanonicalPath path)}))
+ (u/file (config-dir conf) (:kpa_dir conf) (:shadow_path conf)))
+
+(defn gallery-db-file
+ "Get the gallery DB File from a config map."
+ [conf]
+ (u/file (config-dir conf) (:gal_db_path conf)))
+
+(defn db-spec ;; maybe move to another namespace
+ "Get a DB spec from a File."
+ [f]
+ {:classname "org.sqlite.JDBC"
+ :subprotocol "sqlite"
+ :subname (.getCanonicalPath f)})
@@ -0,0 +1,43 @@
+-- Warning: File will be split on semicolons
+
+CREATE TABLE metadata (
+ 'version' int,
+ 'lastconfig' text
+);
+
+CREATE TABLE images (
+ 'imageID' integer,
+ 'md5' text(32),
+ 'width' int,
+ 'height' int,
+ 'angle' int,
+ 'label' text,
+ 'description' text,
+ 'stackOrder' int,
+ 'stackID' int,
+ 'startDate' datetime,
+ 'endDate' datetime,
+ 'added' datetime default NULL,
+ PRIMARY KEY (imageID)
+);
+
+CREATE TABLE categories (
+ catID int,
+ catName text,
+ PRIMARY KEY (catID)
+);
+
+CREATE TABLE tags (
+ catID int,
+ tagID int,
+ tagName text,
+ PRIMARY KEY (catID, tagID)
+);
+
+CREATE TABLE imagetags (
+ imageID int,
+ catID int,
+ tagID int,
+ implicit boolean not null,
+ PRIMARY KEY (imageID,catID,tagID)
+);
@@ -4,7 +4,7 @@ function for this."
(:refer-clojure :exclude [read])
(:require [clojure.java.jdbc :as sql]
clojure.java.jdbc.internal
- kpawebgen.config)
+ [kpawebgen.config :as cnf])
(:use [org.timmc.handy :only (version-norm)]
[slingshot.slingshot :only [throw+]]))
@@ -35,7 +35,7 @@ Throws (via slingshot):
localweb can't handle"
[conf]
(binding [clojure.java.jdbc.internal/*as-key* str]
- (sql/with-connection (kpawebgen.config/db-spec conf)
+ (sql/with-connection (cnf/db-spec (cnf/shadow-db-file conf))
(sql/with-query-results r
["SELECT `version` FROM `metadata`"]
;; TODO: check for table and column existence

0 comments on commit e89807b

Please sign in to comment.