Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
161 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
package com.geteit.db | ||
|
||
import android.database.sqlite.{SQLiteDatabase, SQLiteOpenHelper} | ||
import com.geteit.util.Log._ | ||
|
||
trait DaoDB { self: SQLiteOpenHelper => | ||
private implicit val tag: LogTag = "DaoDB" | ||
|
||
val daos: Seq[Dao[_, _]] | ||
val migrations: Seq[Migration] | ||
|
||
override def onCreate(db: SQLiteDatabase): Unit = | ||
override def onCreate(db: SQLiteDatabase): Unit = { | ||
verbose(s"onCreate()") | ||
daos.foreach { dao => | ||
verbose(s"creating table: ${dao.createTableSql}") | ||
db.execSQL(dao.createTableSql) | ||
dao.table.indexes foreach { index => | ||
db.execSQL(index.createIndexSql(dao.table.name)) | ||
} | ||
} | ||
} | ||
|
||
override def onUpgrade(db: SQLiteDatabase, from: Int, to: Int): Unit = | ||
override def onUpgrade(db: SQLiteDatabase, from: Int, to: Int): Unit = { | ||
verbose(s"onUpgrade($from -> $to)") | ||
new Migrations(migrations: _*).migrate(this, from, to)(db) | ||
} | ||
|
||
def dropAllTables(db: SQLiteDatabase): Unit = | ||
daos.foreach { dao => db.execSQL(dao.dropTableSql) } | ||
daos.foreach { dao => | ||
db.execSQL(dao.dropTableSql) | ||
dao.table.indexes foreach { index => | ||
db.execSQL(index.dropIndexSql(dao.table.name)) | ||
} | ||
} | ||
} |