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
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
apply plugin: 'kotlin-kapt' | |
android { |
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
package com.merttoptas.roomexample | |
import androidx.room.ColumnInfo | |
import androidx.room.Entity | |
import androidx.room.PrimaryKey | |
@Entity(tableName = "note_table") | |
data class Note( | |
@ColumnInfo(name ="title") | |
var title:String, |
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
@Dao | |
interface NoteDao { | |
@Query("SELECT * FROM note_table") | |
fun getAllNotes(): List<Note> | |
@Insert | |
fun insertAll(vararg note: Note) | |
@Query("DELETE from note_table where noteId = :noteId") |
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
@Database(entities = [Note::class],version = 1) | |
abstract class AppDatabase: RoomDatabase() { | |
abstract fun notedao(): NoteDao | |
} |
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
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
//Create a notes in list | |
val notes:List<Note> | |
val db:AppDatabase= Room.databaseBuilder(this,AppDatabase::class.java,"notes") |
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
class CreateNoteActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_create_note) | |
supportActionBar!!.setDisplayHomeAsUpEnabled(true) | |
val db:AppDatabase= Room.databaseBuilder(applicationContext,AppDatabase::class.java,"notes") |
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
import 'dart:async'; | |
import 'package:floor/floor.dart'; | |
import 'package:path/path.dart'; | |
import 'package:sqflite/sqflite.dart' as sqflite; | |
import 'package:floor_example/model/Student.dart'; | |
import 'package:floor_example/db/StudentDao.dart'; | |
part 'database.g.dart'; |
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
import 'package:floor/floor.dart'; | |
@entity | |
class Student { | |
@PrimaryKey(autoGenerate: true) | |
final int id; | |
final String name; | |
final String school; |
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
mport 'package:floor_example/model/Student.dart'; | |
import 'package:floor/floor.dart'; | |
@dao | |
abstract class StudentDao { | |
@Query('SELECT * FROM student WHERE id = :id') | |
Future<Student> findTaskById(int id); | |
@Query('SELECT * FROM student') | |
Future<List<Student>> findAllTasks(); |
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
import 'dart:async'; | |
import 'package:floor/floor.dart'; | |
import 'package:path/path.dart'; | |
import 'package:sqflite/sqflite.dart' as sqflite; | |
import 'package:floor_example/model/Student.dart'; | |
import 'package:floor_example/db/dao/StudentDao.dart'; | |
part 'database.g.dart'; // the generated code will be there |
OlderNewer