

Expo sqlite tutorial code#
The SQLITE_BUSY result code differs from SQLITE_LOCKED in that SQLITE_BUSY indicates a conflict with a separate database connection, probably in a separate process, whereas SQLITE_LOCKED indicates a conflict within the same database connection (or sometimes a database connection with a shared cache).

See also: SQLITE_BUSY_RECOVERY and SQLITE_BUSY_SNAPSHOT. The BEGIN IMMEDIATE command might itself return SQLITE_BUSY, but if it succeeds, then SQLite guarantees that no subsequent operations on the same database through the next COMMIT will return SQLITE_BUSY. To avoid encountering SQLITE_BUSY errors in the middle of a transaction, the application can use BEGIN IMMEDIATE instead of just BEGIN to start a transaction.
Expo sqlite tutorial update#
The sqlite3_busy_timeout() and sqlite3_busy_handler() interfaces and the busy_timeout pragma are available to process B to help it deal with SQLITE_BUSY errors.Īn SQLITE_BUSY error can occur at any point in a transaction: when the transaction is first started, during any write or update operations, or when the transaction commits. Process B will need to wait for process A to finish its transaction before starting a new transaction. The SQLITE_BUSY result code indicates that the database file could not be written (or in some cases read) because of concurrent activity by some other database connection, usually a database connection in a separate process.įor example, if process A is in the middle of a large write transaction and at the same time process B attempts to start a new write transaction, process B will get back an SQLITE_BUSY result because SQLite only supports one writer at a time. rollbackTransaction ( ) Įxport default db quick googling tells me this: See an example in db.js for example of migration function and prepare function. Will receive separate Connection instance MigrateFn Similar to prepareConnFn but for migration purposes (to prepare and update tables). Function receives a Connection instance,Įxecute and transaction methods will wait for resolve of returned promise. PrepareConnFn Async function to execute after connecting to database. Which has execute method with signature as aboveĬonstructor of Database class takes database name as first parameter and optional object as second. Callback function receives an instance of Connection class Transaction method takes an async function as parameter. Documentationĭatabase class has two methods - execute (to execute single statement without transaction) and transaction(cb) to execute few statements inside a transactionĮxecute method takes an SQL string as first parameter and array of values to replace ? symbols as second parameter If you find it difficulty for creating data types dynamically in your sqlite db, you can find the file in path: android/app/src/main/assets/Modify the data types using sqlite browser.With expo-sqlite it's not possible to execute few depending statements inside single transaction - db.transactionĭoes not work with async/promise and tx.executeSql just enqueues sql statement but does not execute it. In my case, i had all text values, you can tweak and modify data types in SQlite as per your api response. const result = await createTable(values) Ĭonst result = await insertIfNotExists(values) Return new Promise((resolve, reject) => Īnd call these methods in your service file(where you are calling the api) and pass the values. "CREATE TABLE IF NOT EXISTS tb_user (ID_user INTEGER PRIMARY KEY, username TEXT, senha TEXT, ID_empresa INT, nome_empresa TEXT, status INT) " I'm trying to save data from an API to a table in SQLite database.

(my app is with expo sqlite and expo react native)
