SQL queries (Credits)

Preface

Introduction

Room is a robust SQL mapping library

Features

Persistence Spectrum

Persistence Spectrum

Anatomy of Room

Room Architecture Diagram

Database

Database Access Objects (DAO)

Entity

Adding it to your project

compile "android.arch.persistence.room:runtime:1.0.0-rc1"// Java 
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-rc1"
// Kotlin
kapt "android.arch.persistence.room:compiler:1.0.0-rc1"

Let’s code with Room!

Entity

User class with @Entity annotation
User entity with column info
User entity with composite primary keys
User entity with ignore

Database Access Objects (DAO)

DAO for user entity
Query with LiveData

Database

Database
Getting database instance

Relations

Nested Objects

Users entity with embedded address
Address POJO
Schema of users table

Foreign Key

User entity with foreign key
Address entity
One to one relation between user and address
UserWithAddress
SQL query for users and city (address)

Testing

Pro-tips

Conclusion

Room is like Retrofit for database

Update: What’s next?

Google Developer Expert @ Android | Android Engineer @ Clue | Instructor @Caster.IO

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store