Fork me on GitHub
#datalog
<
2022-06-05
>
Charles Fourdrignier09:06:41

Hello everybody, I'm playing a bit with Datalog (with Datascript) on some existing code. This code is sort of "SQL oriented" and I have some difficulties to escape this mental model. My data is a "test result" and looks like this right now.

{
    :team-id "ABDEF" ;; identity of the team for which the test ran : foreign key 
    :test {
        :title "My first test" ;; identity of the test
        :campaign-name "My first campaign" ;; identity of the campaign containing the test : foreign key
    }
    ;; data of the test result
}
From my current understanding of Datalog queries, it seems it would be easier to transform my data to create real "refs" in the data.
{
    :team { :team/id "ABDEF" }
    :test {
        :title "My first test" ;; Should be renamed :test/title in the process...
        :campaign {:campaign/name "My first campaign"}
    }
    ;; data of the test result
}
Is this the "Datalog way" of doing things ?

val_waeselynck12:06:48

Yup, the 2nd data structure seems DataScript-friendly to me 🙂

val_waeselynck12:06:10

But your issue is more related to the data model of DataScript and its transactions language than to Datalog.

val_waeselynck12:06:48

More precisely, the above code will write correctly to DataScript if: 1. :team is a cardinality-one, ref-typed attribute from TestResult to Team (you might want to rename to :test-result/team) 2. :test is a cardinality-one, ref-typed attribute from TestResult to Test (you might want to rename to :test-result/test) 3. :campaign is a cardinality-one, ref-typed attribute from Test to Campaign (you might want to rename to :test/campaign) 4. :team/id is a :db.unique/identity attribute for identifying a Team 5. :title is a :db.unique/identity attribute for identifying a Team (you might want to rename to :test/title) 6. :campaign/name is a :db.unique/identity attribute for identifying a Campaign

Charles Fourdrignier12:06:03

I totally missed the point on the namespace "test-result" for team and test, but you're absolutely right. Thanks for the detailed response !