 ;
 
 ; Insert probe & return id
-(defn- insert-probe [exp name]
-  (let [pid (insert probes (values {:eid exp :name name}))]
-    pid))
+(defn- insert-field [exp name]
+  (let [id (insert field (values {:dataset_id exp :name name}))]
+    id))
 
 (defn- insert-scores [slist]
-  (let [sid (insert scores (values {:expScores slist}))]
-    sid))
-
-(defn- insert-join [pid i sid]
-  (insert joins (values {:pid pid :i i :sid sid})))
+  (let [score-id (insert scores (values {:scores slist}))]
+    score-id))
+
+(defn- insert-field-score [field-id i score-id]
+  (insert field_score (values {:field_id field-id :i i :score_id score-id})))
 
 (defn- table-writer-default [dir f]
-  (f {:insert-probe insert-probe
+  (f {:insert-field insert-field
          :insert-score insert-scores
-         :insert-join insert-join
+         :insert-field-score insert-field-score
          :encode score-encode
          :key ahashable}))
 

(defn- exec-statements [stmts]
  (dorun (map exec-raw stmts)))

; Intersect experiment samples with the given set of samples.
(defn exp-samples-in-list [exp samps]
  (select exp_samples (fields :i :name)
          (where  {:experiments_id exp}) (where (in :name samps))))

(defn sample-bins [samps]
  (set (map #(quot (% :I) bin-size) samps)))

(defn exp-by-name [exp]
  (let [[{id :ID}]
        (select experiments (fields "id") (where {:name (str exp)}))] ; XXX shoul str be here, or higher in the call stack?
    id))

; merge bin number and bin offset for a sample.

;    nil))
;
;
;(defmeta dataset
;  :id "INT NOT NULL AUTO_INCREMENT PRIMARY KEY"
;  :name "varchar(255) NOT NULL UNIQUE"
;  :probeMap "varchar(255)"
