How to create multiple tables in a database in sqflite?

后端 未结 6 1940
礼貌的吻别
礼貌的吻别 2021-01-11 11:51

Im building and app with flutter that uses SQLite database. I have created first table using this piece of code:

 void _createDb(Database db, int newVersion)         


        
6条回答
  •  孤独总比滥情好
    2021-01-11 11:55

    yes you can do it

     void _createDb(Database db, int newVersion) async {
     await db.execute('''
       create table $carTable (
        $columnCarId integer primary key autoincrement,
        $columnCarTitle text not null
       )''');
     await db.execute('''
       create table $userTable(
        $userId integer primary key autoincrement,
        $name text not null
       )''');
      }
    

    but to speed up the process, let's assume we have 10 tables, you could use the batch this way

    void _createDb(Database db, int newVersion) async {
    Batch batch = db.batch();
    batch.execute("Your query-> Create table if not exists");
    batch.execute("Your query->Create table if not exists");
    List res = await batch.commit();
    //Insert your controls
    }
    

提交回复
热议问题