0

The basic construct of creating a single table in sqlite db is as follows:

const db = SQLite.openDatabase('students.db')

export const init = () => {
  const promise = new Promise((resolve, reject) => {
    db.transaction((tx) => {
      tx.executeSql(
        'CREATE TABLE IF NOT EXISTS stud(id INTEGER PRIMARY KEY, name TEXT NOT NULL);',
        [],
        () => {
          resolve()
        },
        (_, err) => {
          reject(err)
        }
      )
    })
  })
  return promise
}

However how to create another table (say) teachers?

1 Answer 1

2

I currently have no setup to test it but in general, this should work.

export const init = async () => {
  const promise = new Promise((resolve, reject) => {
    db.transaction(async (tx) => {
      await tx.executeSql(
        'CREATE TABLE IF NOT EXISTS stud(id INTEGER PRIMARY KEY, name TEXT NOT NULL);')
await tx.executeSql(
        'CREATE TABLE IF NOT EXISTS teachers(id INTEGER PRIMARY KEY, name TEXT NOT NULL);')
resolve();
    })
  })
  return promise
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.