Commit graph

38 commits

Author SHA1 Message Date
Nick Alexander
9aed24ae39 Fix :db.unique/value, which should be per (a, v) pair, not per v-value. 2016-08-19 12:27:40 -07:00
Nick Alexander
3dfdea99e7 Implement parts: Make the DB allocate and persist entity IDs.
This implementation is inefficient because each allocated temporary ID
touches the database, but it's enough to allow to re-open DBs.
2016-08-19 12:27:39 -07:00
Nick Alexander
29d409be64 Tag values with value type tags in SQLite. 2016-08-19 12:27:39 -07:00
Nick Alexander
b4e5c88d6a Add d/q; make query minimally schema aware. 2016-08-19 12:27:39 -07:00
Nick Alexander
cfe753a3bd Add d/{ident,entid} for mapping between keyword idents and integer entids. 2016-08-19 12:27:39 -07:00
Richard Newman
d687d4221a Clarify d/<connect. 2016-08-19 12:27:39 -07:00
Richard Newman
1a54cec1ba Use correct view for fulltext+non-fulltext. 2016-08-05 16:29:21 -07:00
Richard Newman
fc845a9950 Implement basic fulltext binding. r=nalexander 2016-08-05 13:04:06 -07:00
Richard Newman
4c2230929e Turn Source into a protocol. Allow source->from to switch on attribute. r=nalexander 2016-08-05 13:03:48 -07:00
Nick Alexander
c948902c52 Follow-up: Extract datomish.transact.explode.
This required pushing the ID literal out of transact.  I elected to put
them in DB, since literal allocation will end up in IDB eventually.
2016-08-04 17:54:50 -07:00
Nick Alexander
d8c976c3ad Follow-up: split the monolith!
This was a little more tricky than might be expected because the
initialization process uses the transactor to bootstrap the database.
Since Clojure doesn't accept mutually recursive modules, this
necessitated a third module, namely "db-factory", which uses both "db"
and "transact".  While I was here, I started an "api" module, to paper
over the potentially complicated internal module structure for external
consumers.  In time, this "api" module may also grow CLJS-specific JS
transformations.
2016-08-04 17:54:32 -07:00
Nick Alexander
73b155cfdc Follow-up: don't accept schema when creating DB.
This schema was already ignored.
2016-08-04 16:34:48 -07:00
Nick Alexander
44db8116bf Handle nested maps, sequences in maps, and reverse references. 2016-08-04 14:26:20 -07:00
Nick Alexander
d9a8cb0d6a Don't accept user-provided tx values.
This agrees with Datomic.  DataScript allows tx values, possibly to
allow reconstructing DBs from Datom streams, but appears to handle
user-provided tx values in the transactor inconsistently.
2016-08-04 14:26:20 -07:00
Nick Alexander
38545f6efc Add :tx and :txInstant to TxReport; accept :db/tx in transactor; allow to set :db/txInstant.
The implementation of :db/tx is special and may need to change over
time.  We add it as a special ident, with value the current transaction
entity ID, specified per-transaction.  This works well right now but
introduces some (internal) ordering requirements that may need to be
loosened.
2016-08-04 14:26:20 -07:00
Nick Alexander
f25838a1eb Support :db/fulltext true.
Internally, we use SQLite's FTS4 to maintain a fulltext_values table of
unique "text" values.  Fulltext indexed datoms have value v that is the
rowid into fulltext_values.  We manually maintain the map between rowid
and value in the transactor.

For convenience, we expose two views interpolating the real text values
into the datoms structure.
2016-08-04 14:26:20 -07:00
Nick Alexander
13f33a4915 Unify test pattern around "(... -after tx0)". 2016-08-04 14:26:20 -07:00
Nick Alexander
296c9cb436 Bootstrap DB schema; persist and restore schema from materialized views. 2016-08-04 14:26:20 -07:00
Nick Alexander
6a8739bd2f Accept new schema fragments via :db.part/db :db.install/attribute. 2016-08-04 14:26:20 -07:00
Nick Alexander
9497d69b44 Respect :db/unique constraints; test upserts.
This version includes SQLite-level unique indexes; these should never be
needed.  I've included them as a fail-safe while testing; they'll help
us catch errors in the transaction layer above.
2016-08-04 14:26:20 -07:00
Nick Alexander
80742242e2 Fix cljs 2016-08-04 14:26:20 -07:00
Nick Alexander
7a90c43a5a Map valueTypes to SQLite encodings.
In the future, we might add a layer of indirection, hashing values to
avoid duplicating storage, or sorting URLs, or handling fulltext indexed
values differently, or ...
2016-08-04 14:26:20 -07:00
Nick Alexander
43423b7d0a Validate value types. 2016-08-04 14:26:20 -07:00
Nick Alexander
661e7ed123 Allow to add new :db/ident mappings. 2016-08-04 14:26:20 -07:00
Nick Alexander
baec3815b0 Implement transactions. 2016-08-04 14:26:20 -07:00
Richard Newman
8a77dcd8f0 Implement simple 'or' clauses. r=nalexander 2016-07-27 17:04:32 -07:00
Richard Newman
1ad67a03eb Add tests and comments for clause ordering. 2016-07-26 11:19:51 -07:00
Richard Newman
feaca75a74 Add tests for joins and not-clauses. 2016-07-26 10:51:13 -07:00
Richard Newman
72f7c8e1a3 Fix test-raise. 2016-07-26 10:50:55 -07:00
Richard Newman
42361c1e5e Implement negation, predicates, external scalar bindings, <?q. r=nalexander 2016-07-25 17:08:00 -07:00
Nick Alexander
13dc1cc9b6 Take more general raise from DataScript. 2016-07-19 10:35:35 -07:00
Nick Alexander
bf080ced3c Part 2: Add ISQLiteConnectionFactory and CLJC test that uses it. 2016-07-13 18:19:22 -07:00
Nick Alexander
cca5010671 Part 1: Fix testing errors.
Some of these were just typos, but `with-open` was fatally flawed on
CLJS (we couldn't call `.close` at all), and `deftest-async` was hiding
all failures (due to a typo).
2016-07-13 18:19:22 -07:00
Nick Alexander
900e77862e Implement database on top of SQLite connection. r=rnewman
We would prefer to talk about a knowledge base on top of a database, but
all the Datomic and DataScript code (and symbols, like :db/add, etc)
refer to the "database of datoms", so let's roll with that nomenclature
and try to be specific that the persistent storage-layer is SQLite.
This will become more clear when we actually use SQLite's unique
capabilities for text indexing.
2016-07-13 12:37:23 -07:00
Richard Newman
db68a714f6 First pass at translating Datalog queries into SQL. r=nalexander
Signed-off-by: Richard Newman <rnewman@twinql.com>
2016-07-13 09:51:42 -07:00
Nick Alexander
724c37466d Add an SQLite connection abstraction. 2016-07-12 13:56:26 -07:00
Nick Alexander
0a312b4f40 Add an async and async testing framework.
This is a well-worn idea: use a `promise-channel` of `[result nil]` or
`[nil error]` pairs.  The `go-pair` and `<?` macros handle catching
exceptions (important, given that synchronous CLJ code expects to throw
rather than return an error promise or similar), allowing code like:
```
(go-pair
  (let [result (<? (pair-chan-fn))]
    (when (not result)
      (throw (Exception. "No result!")))
    (transform result)))
```
to be expressed naturally.  These are the equivalents of `async` and
`await` in JS.

The implementation is complicated by significant incompatibilities
between CLJ and CLJS.  The solution presented here takes care to
separate the macro definitions into CLJ.  Sadly, this requires
namespacing the per-environment symbols explicitly; but we hope to
minimize such code in files like this.

The most significant restriction to this approach is that consumers must
require the transitive dependencies of the macro-defining modules.  See
the included tests (both CLJ and CLJS) for the appropriate
incantations (for pair-chan, core.async, and test).
2016-07-12 13:56:26 -07:00
Nick Alexander
08f7084d92 Add lein-doo to run ClojureScript tests. 2016-07-06 16:42:40 -07:00