(db) create CRUD model
This commit is contained in:
parent
e649f412d3
commit
2642c4432c
4 changed files with 96 additions and 0 deletions
|
@ -0,0 +1,13 @@
|
|||
package com.keylesspalace.tusky.db;
|
||||
|
||||
import android.arch.persistence.room.Database;
|
||||
import android.arch.persistence.room.RoomDatabase;
|
||||
|
||||
/**
|
||||
* Created by cto3543 on 28/06/2017.
|
||||
*/
|
||||
|
||||
@Database(entities = {TootEntity.class}, version = 2, exportSchema = false)
|
||||
abstract public class AppDatabase extends RoomDatabase {
|
||||
public abstract TootDao tootDao();
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.keylesspalace.tusky.db;
|
||||
|
||||
import android.arch.persistence.room.ColumnInfo;
|
||||
import android.arch.persistence.room.Entity;
|
||||
import android.arch.persistence.room.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Created by cto3543 on 28/06/2017.
|
||||
*/
|
||||
|
||||
@Entity
|
||||
public class MediaEntity {
|
||||
@PrimaryKey
|
||||
private int uid;
|
||||
|
||||
@ColumnInfo(name = "url")
|
||||
private String text;
|
||||
}
|
30
app/src/main/java/com/keylesspalace/tusky/db/TootDao.java
Normal file
30
app/src/main/java/com/keylesspalace/tusky/db/TootDao.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package com.keylesspalace.tusky.db;
|
||||
|
||||
import android.arch.persistence.room.Dao;
|
||||
import android.arch.persistence.room.Delete;
|
||||
import android.arch.persistence.room.Insert;
|
||||
import android.arch.persistence.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by cto3543 on 28/06/2017.
|
||||
*/
|
||||
|
||||
@Dao
|
||||
public interface TootDao {
|
||||
@Query("SELECT * FROM TootEntity")
|
||||
List<TootEntity> loadAll();
|
||||
|
||||
@Query("SELECT * FROM TootEntity WHERE uid IN (:uid)")
|
||||
List<TootEntity> loadAllByUserId(int... uid);
|
||||
|
||||
@Insert
|
||||
long insert(TootEntity users);
|
||||
|
||||
@Insert
|
||||
void insertAll(TootEntity... users);
|
||||
|
||||
@Delete
|
||||
void delete(TootEntity user);
|
||||
}
|
35
app/src/main/java/com/keylesspalace/tusky/db/TootEntity.java
Normal file
35
app/src/main/java/com/keylesspalace/tusky/db/TootEntity.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package com.keylesspalace.tusky.db;
|
||||
|
||||
import android.arch.persistence.room.ColumnInfo;
|
||||
import android.arch.persistence.room.Entity;
|
||||
import android.arch.persistence.room.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Created by cto3543 on 28/06/2017.
|
||||
*/
|
||||
|
||||
@Entity
|
||||
public class TootEntity {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private int uid;
|
||||
|
||||
@ColumnInfo(name = "text")
|
||||
private String text;
|
||||
|
||||
// set get
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(int uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue