question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implementing SQLite to use promises does not work on the second step in a transaction

See original GitHub issue

Summary

I am trying to use promises to reduce the code depth for the SQLite callbacks. However, it appears that the way expo-sqlite is implemented, using immediate it when it starts and completes the first SQL in a transaction, it marks the transaction as “complete” and executing a second SQL in the same transaction hangs.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android iOS

SDK Version (managed workflow only)

40

Environment

Expo CLI 4.5.2 environment info: System: OS: Windows 10 10.0.19043 Binaries: Node: 12.18.0 - ~\scoop\apps\nvm\current\nodejs\nodejs\node.EXE npm: 6.14.4 - ~\scoop\apps\nvm\current\nodejs\nodejs\npm.CMD IDEs: Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7351085 npmPackages: expo: ^40.0.0 => 40.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz => 0.63.2 react-native-web: ^0.16.3 => 0.16.3 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

https://snack.expo.io/@trajano/sqlite-async

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mrmurphycommented, Oct 18, 2022

Can this issue be re-opened? I’m surprised that, when the mainstream idiomatic way to handle async operations in JS/TS is now Async/Await, Expo’s sql library auto-closes transactions after the first line of execution when wrapping promises are used. In my opinion, to make expo-sqlite a viable offering (with respect to developer ergonomics) it’d retain the same operational semantics when called within a promise chain as when called using callbacks.

Ideally, the library would expose a promise-based API in the first place. But promise compatibility at the very least feels essential.

It seems that promises were omitted because the author wanted to follow the design of the WebSQL standard, but that standard has been basically abandoned long ago. I don’t think that conforming to the WebSQL API will help any developers get a productivity boost here, but the opposite.

I ran into this bug a couple of years ago when I tried to use Expo SQLite, and now again when I came back for another try.

Thanks for all your hard work! The Expo team is doing amazing things.

0reactions
github-actions[bot]commented, Jan 27, 2022

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSQL/SQLite - Transaction Lock - LinkedIn
SQL insert to save 2nd record. In this case, by the time you are at step 3 your transaction object is in invalid...
Read more >
Expo SQLite promisse rejection - Stack Overflow
Do something like the following. executarComando(strSql, params = []) { return new Promise((resolve, reject) => { db.transaction((tx) ...
Read more >
Convince me to use better-sqlite3 · Issue #262 - GitHub
Something else you might be interested in is that node-sqlite3 doesn't support transactions unless you use a different database connection for ...
Read more >
Workers and Promises (a.k.a. Worker1 and Promiser) - SQLite
Transactions can only work if the database has only a single user or if all transaction-enclosed SQL code is contained in the same...
Read more >
SQLite - Expo Documentation
To open a new SQLite database using an existing .db file you already have, follow the steps below: 1. Install expo-file-system and expo-asset...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found