0
0
React Nativemobile~5 mins

SQLite with expo-sqlite in React Native - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is expo-sqlite used for in React Native?
It is a library that allows you to use a lightweight SQL database (SQLite) inside your React Native app to store and manage data locally on the device.
Click to reveal answer
beginner
How do you open or create a database using expo-sqlite?
You use SQLite.openDatabase('name.db') which opens the database if it exists or creates it if it doesn't.
Click to reveal answer
intermediate
What method is used to run SQL commands like creating tables or inserting data?
You use db.transaction(tx => { tx.executeSql(sql, params, success, error) }) to run SQL commands inside a transaction.
Click to reveal answer
intermediate
Why do we use transactions when working with expo-sqlite?
Transactions ensure that a group of SQL commands run safely together. If one command fails, the whole transaction can be rolled back to keep data consistent.
Click to reveal answer
intermediate
How can you retrieve data from the database using expo-sqlite?
Inside a transaction, use executeSql with a SELECT query. The results are in the resultSet.rows._array property inside the success callback.
Click to reveal answer
Which function opens or creates a SQLite database in expo-sqlite?
ASQLite.openDatabase('mydb.db')
BSQLite.createDatabase('mydb.db')
CSQLite.connect('mydb.db')
DSQLite.initDatabase('mydb.db')
What is the purpose of the transaction method in expo-sqlite?
ATo open the database connection
BTo backup the database
CTo close the database
DTo run multiple SQL commands safely as a group
Where do you find the rows returned by a SELECT query in expo-sqlite?
AresultSet.records
BresultSet.rows._array
CresultSet.rowsArray
DresultSet.data
Which SQL command creates a new table in expo-sqlite?
ACREATE TABLE IF NOT EXISTS tablename (...)
BNEW TABLE tablename (...)
CMAKE TABLE tablename (...)
DADD TABLE tablename (...)
What happens if one SQL command fails inside a transaction?
AThe database closes automatically
BOnly the failed command is ignored, others continue
CThe whole transaction rolls back and no changes are saved
DThe app crashes
Explain how to create a simple table and insert data using expo-sqlite in React Native.
Think about opening the database, then running SQL commands inside a transaction.
You got /5 concepts.
    Describe how to retrieve and display data from a SQLite database using expo-sqlite.
    Focus on running a SELECT query and accessing the results in the callback.
    You got /5 concepts.