add servers to the new database
This commit is contained in:
parent
a45ae46d31
commit
eb5b4787ed
7 changed files with 82 additions and 31 deletions
|
|
@ -1,18 +1,32 @@
|
|||
package com.dkanada.gramophone.database;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.migration.Migration;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
import com.dkanada.gramophone.model.Server;
|
||||
import com.dkanada.gramophone.model.Song;
|
||||
|
||||
@androidx.room.Database(
|
||||
entities = {
|
||||
Song.class,
|
||||
QueueSong.class
|
||||
QueueSong.class,
|
||||
Server.class
|
||||
},
|
||||
version = 1,
|
||||
version = 2,
|
||||
exportSchema = false
|
||||
)
|
||||
public abstract class JellyDatabase extends RoomDatabase {
|
||||
public abstract QueueSongDao queueSongDao();
|
||||
public abstract SongDao songDao();
|
||||
public abstract ServerDao serverDao();
|
||||
|
||||
public static final Migration Migration2 = new Migration(1, 2) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE servers (id TEXT NOT NULL PRIMARY KEY, name TEXT,"
|
||||
+ "url TEXT, user TEXT, token TEXT)");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.dkanada.gramophone.database;
|
||||
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
|
||||
import com.dkanada.gramophone.model.Server;
|
||||
|
||||
@Dao
|
||||
public interface ServerDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertServer(Server server);
|
||||
|
||||
@Delete
|
||||
void deleteServer(Server server);
|
||||
|
||||
@Query("SELECT * FROM servers WHERE id = :id")
|
||||
Server getServer(String id);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue