JSFiddle - React, Tailwind, and code Playground

by JayData

HTML

<script src="http://include.jaydata.org/jaydata.js"></script>
<script src="http://include.jaystack.net/s.js"></script>

JavaScript

$data.define('Parent', {

    k1: { type: String, key: true },
    k2: { type: String, key: true },
    children: { type: "Array", elementType: "Child", inverseProperty: "master" }
    
});

$data.define('Child', {

    k1: { type: String, key: true },
    k2: { type: String, key: true },
    master: { type: "Parent", inverseProperty: "children" }
    
});

$data.EntityContext.extend("db", {
    ParentSet: { type: $data.EntitySet, elementType: Parent },
    ChildrenSet: { type: $data.EntitySet, elementType: Child },
 });

var ctx = new db({ name: "webSql", databaseName: "Testing"});

ctx.onReady()
.then(function() {
    
    console.log(ctx.ParentSet.filter('it.k1 == "a"').include('children').toTraceString().sqlText);

    console.log(ctx.ChildrenSet.filter('it.k1 == "a"').include('master').toTraceString().sqlText);

    
    ctx.ParentSet.filter('it.k1 == "a"').include('children').toArray()
    .then(function(r) {
        console.log(r);
        
    });
});