instant-local-throwaway
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -58,5 +58,5 @@ import { createDB, save } from "../src/db"; | ||
query({ user: { $: { where: { name: "Stopa" } }, bookshelf: {} } }, db) | ||
).toEqual([ | ||
{ bookshelf: [{ id: "b", title: "Favs" }], id: "a", name: "Stopa" }, | ||
]); | ||
).toEqual({ | ||
user: [{ bookshelf: [{ id: "b", title: "Favs" }], id: "a", name: "Stopa" }], | ||
}); | ||
}); |
@@ -38,3 +38,3 @@ import zenecaTriples from "../data/zenecaTriples.json"; | ||
query({ user: {} }, db) | ||
.map((x) => x.id) | ||
.user.map((x) => x.id) | ||
.sort() | ||
@@ -45,11 +45,13 @@ ).toEqual(["2", "3", "47", "622"]); | ||
test("Simple Query With Where", () => { | ||
expect(query({ user: { $: { where: { handle: "stopa" } } } }, db)).toEqual([ | ||
{ | ||
createdAt: "2021-01-07 18:50:43.447955", | ||
email: "stepan.p@gmail.com", | ||
fullName: "Stepan Parunashvili", | ||
handle: "stopa", | ||
id: "2", | ||
}, | ||
]); | ||
expect(query({ user: { $: { where: { handle: "stopa" } } } }, db)).toEqual({ | ||
user: [ | ||
{ | ||
createdAt: "2021-01-07 18:50:43.447955", | ||
email: "stepan.p@gmail.com", | ||
fullName: "Stepan Parunashvili", | ||
handle: "stopa", | ||
id: "2", | ||
}, | ||
], | ||
}); | ||
}); | ||
@@ -68,20 +70,22 @@ | ||
) | ||
).toEqual([ | ||
{ | ||
bookshelf: [ | ||
{ | ||
desc: "", | ||
id: "47-0", | ||
name: "Short Stories", | ||
order: 0, | ||
}, | ||
{ desc: "", id: "47-1", name: "Nonfiction", order: 1 }, | ||
], | ||
createdAt: "2021-01-09 18:53:07.993689", | ||
email: "reichertjalex@gmail.com", | ||
fullName: "Alex", | ||
handle: "alex", | ||
id: "47", | ||
}, | ||
]); | ||
).toEqual({ | ||
user: [ | ||
{ | ||
bookshelf: [ | ||
{ | ||
desc: "", | ||
id: "47-0", | ||
name: "Short Stories", | ||
order: 0, | ||
}, | ||
{ desc: "", id: "47-1", name: "Nonfiction", order: 1 }, | ||
], | ||
createdAt: "2021-01-09 18:53:07.993689", | ||
email: "reichertjalex@gmail.com", | ||
fullName: "Alex", | ||
handle: "alex", | ||
id: "47", | ||
}, | ||
], | ||
}); | ||
}); | ||
@@ -100,34 +104,36 @@ | ||
) | ||
).toEqual([ | ||
{ | ||
_user: [ | ||
{ | ||
createdAt: "2021-01-09 18:53:07.993689", | ||
email: "reichertjalex@gmail.com", | ||
fullName: "Alex", | ||
handle: "alex", | ||
id: "47", | ||
}, | ||
], | ||
desc: "", | ||
id: "47-0", | ||
name: "Short Stories", | ||
order: 0, | ||
}, | ||
{ | ||
_user: [ | ||
{ | ||
createdAt: "2021-01-09 18:53:07.993689", | ||
email: "reichertjalex@gmail.com", | ||
fullName: "Alex", | ||
handle: "alex", | ||
id: "47", | ||
}, | ||
], | ||
desc: "", | ||
id: "47-1", | ||
name: "Nonfiction", | ||
order: 1, | ||
}, | ||
]); | ||
).toEqual({ | ||
bookshelf: [ | ||
{ | ||
_user: [ | ||
{ | ||
createdAt: "2021-01-09 18:53:07.993689", | ||
email: "reichertjalex@gmail.com", | ||
fullName: "Alex", | ||
handle: "alex", | ||
id: "47", | ||
}, | ||
], | ||
desc: "", | ||
id: "47-0", | ||
name: "Short Stories", | ||
order: 0, | ||
}, | ||
{ | ||
_user: [ | ||
{ | ||
createdAt: "2021-01-09 18:53:07.993689", | ||
email: "reichertjalex@gmail.com", | ||
fullName: "Alex", | ||
handle: "alex", | ||
id: "47", | ||
}, | ||
], | ||
desc: "", | ||
id: "47-1", | ||
name: "Nonfiction", | ||
order: 1, | ||
}, | ||
], | ||
}); | ||
}); |
{ | ||
"name": "instant-local-throwaway", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "This is an experiment for instant", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,3 +23,3 @@ import * as datalog from "./datalog"; | ||
export function isAttrJoinFor(attr, namespaceB) { | ||
return attr.startsWith('ref$') && attr.endsWith(`$${namespaceB}`); | ||
return attr.startsWith("ref$") && attr.endsWith(`$${namespaceB}`); | ||
} | ||
@@ -105,4 +105,3 @@ | ||
function expandSelect(form, db, eid) { | ||
const top = Object.keys(form)[0]; | ||
function expandSelect(top, query, db, eid) { | ||
const attrTups = hackFilterForJustAttribute( | ||
@@ -112,3 +111,3 @@ datalog.query(buildAttrTupQuery(eid), db) | ||
const m = attrTupsToMap(attrTups); | ||
const refNamespaces = getRefNamespaces(form[top]); | ||
const refNamespaces = getRefNamespaces(query); | ||
refNamespaces.forEach((refNamespace) => { | ||
@@ -119,3 +118,3 @@ const refEids = new Set( | ||
m[refNamespace] = [...refEids].map((refEid) => | ||
expandSelect({ [refNamespace]: form[top][refNamespace] }, db, refEid) | ||
expandSelect(refNamespace, query[refNamespace], db, refEid) | ||
); | ||
@@ -126,8 +125,13 @@ }); | ||
export function query(form, db) { | ||
const top = Object.keys(form)[0]; | ||
function queryPart(top, query, db) { | ||
const eids = new Set( | ||
datalog.query(buildWhereQuery(top, form[top]?.$?.where), db) | ||
datalog.query(buildWhereQuery(top, query?.$?.where), db) | ||
); | ||
return [...eids].map((eid) => expandSelect(form, db, eid)); | ||
return [...eids].map((eid) => expandSelect(top, query, db, eid)); | ||
} | ||
export function query(form, db) { | ||
return Object.fromEntries( | ||
Object.keys(form).map((top) => [top, queryPart(top, form[top], db)]) | ||
); | ||
} |
1464619
23844