简体   繁体   English

您可以从SQLite数据库返回带有JavaScript的SQLResultSet吗?

[英]Can you return an SQLResultSet with JavaScript from an SQLite database?

I'm trying to create a little plugin that will make working with SQLite databases a little easier. 我正在尝试创建一个小插件,这将使使用SQLite数据库更加容易。 I've got the basic CRUD functions except for selecting data from the database. 除了从数据库中选择数据外,我具有基本的CRUD功能。

I would like to return the selected data from the executeSql function, but it seems all I can do is call another method and not just return the data. 我想从executeSql函数返回选择的数据,但是似乎我所能做的就是调用另一个方法,而不仅仅是返回数据。

So what I'd like to do is: 所以我想做的是:

var data = $(window).dbPlugin( 'select', '*', 'tableName', 'conditions' );

Then I would like to work with the "data" variable as the SQLResultSet from the query. 然后,我想使用“数据”变量作为查询的SQLResultSet。 However, the transaction seems to only allow me to call a data handler method and not just return the result. 但是,该事务似乎仅允许我调用数据处理程序方法,而不仅返回结果。

testDB.transaction(  
    function ( transaction ) {  
        transaction.executeSql( sql, [], dataHandler, errorHandler);  
    }  
);

function dataHandler( transaction, results ) {
    // Now I can work with the "results" as the SQLResultSet
}

Any ideas how to just return the selected data or if it's even possible? 有什么想法如何只返回所选的数据,或者什至有可能吗?

SQLlite is asynchronous, and there isn't any way to avoid that. SQLlite是异步的,没有任何方法可以避免这种情况。 You could pass in the function you want to be called as your callback into your .dbPlugin method. 您可以将要调用的函数作为回调传递给.dbPlugin方法。 After conditions pass another value which is a function to be called after the query is run. 条件传递后,另一个值是运行查询后要调用的函数。 Then set data in your callback function. 然后在回调函数中设置数据。

It's pretty annoying, I recently wrote something like you are writing on my last project. 这很烦人,我最近写的东西就像您在我的上一个项目中写的一样。 I used a jQuery plugin called blockUI that would essentially block the interface during SQL calls which made it appear a little more 'synchronous' 我使用了一个名为blockUI的jQuery插件,该插件实际上会在SQL调用期间阻止该接口,从而使该接口看起来更加“同步”

Good luck. 祝好运。

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

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