javascript - sqlite synchronous - Stack Overflow

i have been using sqlite, phonegap, javascript and i m in need of fetching information from the sqlite

i have been using sqlite, phonegap, javascript and i m in need of fetching information from the sqlite db.

I am able to fetch all info i need, insert, update, etc.

The problem is javascript works asynchronously. That is it is processing all other succeeding statements before all the necessary info from database gets fetched.

i have tried using callbacks all along and i am tired of it since there are difficulty in using loops. (not able to use sqlite queries within loops since loop gets iterated before the current sqlquery gets processed which is not what i want)

is it possible to do these db operations synchronously?

UPDATE Found out a new solution from here: webkit executesql sentence and loop problem

i have been using sqlite, phonegap, javascript and i m in need of fetching information from the sqlite db.

I am able to fetch all info i need, insert, update, etc.

The problem is javascript works asynchronously. That is it is processing all other succeeding statements before all the necessary info from database gets fetched.

i have tried using callbacks all along and i am tired of it since there are difficulty in using loops. (not able to use sqlite queries within loops since loop gets iterated before the current sqlquery gets processed which is not what i want)

is it possible to do these db operations synchronously?

UPDATE Found out a new solution from here: webkit executesql sentence and loop problem

Share Improve this question edited May 23, 2017 at 12:31 CommunityBot 11 silver badge asked Mar 26, 2013 at 13:49 Vignesh T.V.Vignesh T.V. 1,8604 gold badges30 silver badges50 bronze badges 5
  • Check out caolan/async to help you manage your async operations (such as doing async operiations in a loop in series). – Chad Commented Mar 26, 2013 at 13:57
  • Have you figured out how to use asynchronous functions inside a loop? I have exactly that problem currently – Post Self Commented Feb 24, 2018 at 19:39
  • @kim366 What I ended up finally doing is remove loops and change it all to function calls which was not elegant. You can try the new await function in javascript to help you out: developer.mozilla/en-US/docs/Web/JavaScript/Reference/… Or you can read this article: blog.lavrton./… – Vignesh T.V. Commented Feb 24, 2018 at 20:11
  • @VigneshT.V. Yup, that's what I'm attempting to do. I switched to sqlite (from sqlite3), which uses promises. Still trying to get it to work, but it seems promising; pun not intended. – Post Self Commented Feb 24, 2018 at 20:40
  • Finally got it working! With await you can just make the asynchronous stuff synchronous and not get a headache with all of this – Post Self Commented Feb 25, 2018 at 8:19
Add a ment  | 

2 Answers 2

Reset to default 2

No, but there's a library that may help...

http://html5sql./

I've just started using it myself and it allows you to execute multiple or single SQL requests, with 1 callback. It may be just what you need :)

You can use Siminov Framework. It allows you to make both Synchronous/Asynchronous calls to the native SQLite database. It supports most of the Hybrid Frameworks such as (Cordova, React Native, Xamarin)

However if you are building a Hybrid Apps using JavaScript, then I would remend to use Asynchronous calls because it has a performance advantage over Synchronous calls.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742348507a4427034.html

相关推荐

  • javascript - sqlite synchronous - Stack Overflow

    i have been using sqlite, phonegap, javascript and i m in need of fetching information from the sqlite

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信