I am implementing a service in which each user must have their own json / document database. In addition to the fact that the user can request json documents using an example, the database must also support ACID transactions involving several documents, so I canceled the use of Couch / Mongo or other NoSQL databases (cannot use RavenDB, since it should work in Unix- systems).
With that in mind, I'm trying to figure out a way to implement this in addition to the SQL database. Here is what I have come up with so far:
CREATE TABLE documents (
id INTEGER PRIMARY KEY,
doc TEXT
);
CREATE TABLE indexes (
id INTEGER PRIMARY KEY,
property TEXT,
value TEXT,
document_id INTEGER
)
Each user will have a database with these two tables, and the user will have to indicate which fields he needs to request so that the system can correctly fill in the Indexes table. Therefore, if user "A" sets up his account to include queries by "name" and "age", each time the user inserts a document with the property "name" or "age", the system also inserts the record into "indexes", table, where the column โpropertyโ will contain the name / age, โvalueโ will contain the value of the property, and โdocument_idโ indicates the corresponding document.
For example, let's say a user inserts the following document:
'{"name" : "Foo", "age" 43}'
"" "":
INSERT INTO documents (id,doc) VALUES (1, '{"name" : "Foo", "age" 43}');
INSERT INTO indexes (property, value, document_id) VALUES ('name', 'foo', 1);
INSERT INTO indexes (property, value, document_id) VALUES ('age', '43', 1);
, 'A' :
'{"name": "Foo", "age": 43}'
SQL:
SELECT doc FROM documents
WHERE id IN (SELECT document_id FROM indexes
WHERE document_id IN (SELECT document_id FROM indexes
WHERE property = 'name' AND value = 'Foo')
AND property = 'age' AND value = '43')
:
- , (, 20-30 ), , , SELECT (postgres, mysql...)?
- , / json-?
- ?
- , ACID Unix?