简体   繁体   English

JayData中的关系数据

[英]Relational Data in JayData

I'm re-writing an existing application from WebSql to JayData. 我正在将现有的应用程序从WebSql重写为JayData。 The app is built on WebSql which, being, depricated, needs to be replaced (sooner or later at least). 该应用程序基于WebSql构建,该WebSql已被废弃,需要替换(至少早或晚)。 I re factored all the WebSql into its own Adapter and am now attempting to write a parallel adapter using JayData. 我将所有WebSql分解为它自己的适配器,现在尝试使用JayData编写并行适配器。

What I want to know is how to gracefully handle a sql join . 我想知道的是如何优雅地处理sql join Here's an example 这是一个例子

read: function (display) {
    var sql = "",
        args = [];

    sql += "SELECT table1.table1Id, table1.name, table1Local.UpdateTime ";
    sql += "FROM table1";
    sql += "LEFT OUTER JOIN table1Local ON table1.table1Id = table1Local.table1Id ";
    sql += "WHERE table1Local.Display = ? ";

    args[0] = (display === true ? "1" : "0");

    return database.read(sql, args);
},

I have two jayData entities " table1 " and " table1Local " inside a context. 我在上下文中有两个jayData实体“ table1 ”和“ table1Local ”。 This is my rough cut attempt but it doesn't join the data. 这是我的粗略尝试,但没有加入数据。

   read: function (display) {

        display = display === true ? "1" : "0";

        var dfd = $.Deferred();

        var context = new Table1Context({
            name: config.database.type,
            databaseName: config.database.name
        });

        context.onReady(function(){

            return context.Table1
                .filter(function( t){
                    // We need to use the Display property in the local "table"
                    return t.display == this.display;
                }, {display: display})
                .toArray()
                .then(function (ts) {

                        var data= [];

                        ts.forEach( function(t) {
                            data.push(t);
                        });

                        dfd.resolve(data);
                        return views;
                    });
        });

        return dfd.promise();
    }

I'm a little lost about how make this work properly. 我对如何使它正常工作有些困惑。

I guess you have two entitysets in the Table1Context and two entity definitions, the two entity definitions reference each other. 我猜您在Table1Context中有两个实体集和两个实体定义,这两个实体定义相互引用。 In this case you can change the code of the filter() to 在这种情况下,您可以将filter()的代码更改为

t.table1local.display == this.display;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM