- 
                Notifications
    
You must be signed in to change notification settings  - Fork 518
 
Open
Description
I am working on my first react native app and settled on sqlite for data management. However, I cant initialize the data bank. I always get the error message
(NOBRIDGE) ERROR Database initialization failed: [TypeError: db.transaction is not a function (it is undefined)]
I have expo-sqlite installed. I would appreciate any help.
import * as SQLite from 'expo-sqlite';
const db = SQLite.openDatabaseAsync('workouttracker.db');
export const init = () => {
    const promise = new Promise((resolve, reject) => {
        db.transaction(tx => {
            tx.executeSql(
                'PRAGMA foreign_keys = ON;',
                [],
                () => { },
                (_, error) => {
                    reject(error);
                    return false;
                }
            );
            tx.executeSql(
                `CREATE TABLE IF NOT EXISTS workout_plans (
                      id TEXT PRIMARY KEY,
                      name TEXT NOT NULL,
                      position INTEGER NOT NULL
                    );`,
                [],
                () => { },
                (_, error) => {
                    reject(error);
                    return false;
                }
            );
            tx.executeSql(
                `CREATE TABLE IF NOT EXISTS exercises (
                      num TEXT PRIMARY KEY,
                      plan_id TEXT NOT NULL,
                      muscle TEXT NOT NULL,
                      title TEXT NOT NULL,
                      img TEXT,
                      sets REAL NOT NULL,
                      reps REAL NOT NULL,
                      weight REAL NOT NULL,
                      FOREIGN KEY (plan_id) REFERENCES workout_plans (id) ON DELETE CASCADE
                    );`,
                [],
                () => { },
                (_, error) => {
                    reject(error);
                    return false;
                }
            );
            resolve();
        },
            (error) => reject(error)
        );
    });
    return promise;
}
export default db;
Metadata
Metadata
Assignees
Labels
No labels