A Differential Datalog Implementation in JS
An implementation of Datalog with a focus on managing UIs & UI state.
Features
- Expressive and simple querying syntax
- Differential updates.
- Only run queries on the differences in data. Don't run the query on everything every time.
- Query your Queries
- Run queries on the results of your queries. It's queries all the way down.
- Typed schema and types.
- Works with React.
Examples
Who is the parent of Alice?
import * as datalog from '@datalogui/datalog'
const People = datalog.newTable<{ id: number, name: string }>({
id: datalog.NumberType,
name: datalog.StringType,
})
People.assert({id: 0, name: "Alice"})
People.assert({id: 1, name: "Charles"})
People.assert({id: 2, name: "Helen"})
const ParentOf = datalog.newTable<{ parentID: number, childID: number }>({
parentID: datalog.NumberType,
childID: datalog.NumberType,
})
ParentOf.assert({parentID: 1, childID: 0})
ParentOf.assert({parentID: 2, childID: 0})
const Query = datalog.query<{parentName: string, parentID: number, childID: number}>(({parentName, parentID, childID}) => {
People({name: "Alice", id: childID})
ParentOf({childID, parentID})
People({id: parentID, name: parentName})
})
Query.view().readAllData()
And what if we wanted to query those results?
const QueryQuery = datalog.query<{parentID: number}>(({parentID}) => {
Query({parentID, parentName: "Helen"})
})
QueryQuery.view().readAllData()
Play with this example here.