(db) create CRUD model

This commit is contained in:
torrentcome 2017-06-28 19:33:20 +02:00
parent 22ec554109
commit 464296c9af
4 changed files with 96 additions and 0 deletions

View File

@ -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();
}

View File

@ -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;
}

View 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);
}

View 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;
}
}