android-lecture

android lecture notes

View on GitHub

Room (데이터베이스)

허준영(jyheo@hansung.ac.kr)

Contents

Room 개요

gradle 파일 설정

// Room components
implementation "androidx.room:room-runtime:2.0.0-beta01"
annotationProcessor "androidx.room:room-compiler:2.0.0-beta01"
androidTestImplementation "androidx.room:room-testing:2.0.0-beta01n"

// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-beta01"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0-beta01"

Entity 생성

DAO 생성

DAO 생성

DAO 생성

Database 생성

Database 생성

Migration

.footnote[https://medium.com/androiddevelopers/understanding-migrations-with-room-f01e04b07929]

UI와 연결

UI와 연결

UI와 연결

UI와 연결

전체 예제 코드

bg right:30% w:80%

sqlite3 in adb shell

*C:\Users\jyheo>adb shell
*generic_x86:/ $ run-as com.example.roomexample
generic_x86:/data/data/com.example.roomexample $ ls
cache code_cache databases
*generic_x86:/data/data/com.example.roomexample $ cd databases
generic_x86:/data/data/com.example.roomexample/databases $ ls
school_database school_database-shm school_database-wal
*generic_x86:/data/data/com.example.roomexample/databases $ sqlite3 school_database
SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.
sqlite> .table
android_metadata   room_master_table  student_table      teacher_table
*sqlite> select * from student_table;
16|James
17|John
18|Tom
19|Jessie
21|Eli
22|Sophia
23|Elena
24|test
25|test
26|fgdsfgsdfg
sqlite>