CREATE TABLE hockeyPlayer (
player_number INTEGER NOT NULL,
full_name TEXT NOT NULL
);
CREATE INDEX hockeyPlayer_full_name ON hockeyPlayer(full_name);
INSERT INTO hockeyPlayer (player_number, full_name)
VALUES (15, 'Ryan Getzlaf');
selectAll:
SELECT *
FROM hockeyPlayer;
insert:
INSERT INTO hockeyPlayer(player_number, full_name)
VALUES (?, ?);
定義したAPIは以下のように利用できます。
val driver = AndroidSqliteDriver(Database.Schema, this, "test.db")
val database = Database(driver)
val playerQueries = database.hockeyPlayerQueries
// selectAll
println(playerQueries.selectAll().executeAsList())
// Prints [HockeyPlayer.Impl(15, "Ryan Getzlaf")]
// insert
playerQueries.insert(player_number = 10, full_name = "Corey Perry")
playerQueries.insert(player_number = 999, full_name = "フグ田 サザエ")
// selectAll
println(playerQueries.selectAll().executeAsList())
// Prints [HockeyPlayer.Impl(15, "Ryan Getzlaf"), HockeyPlayer.Impl(10, "Corey Perry")]