SQLDelight in Android: Getting Started

Aug 3 2021 · Kotlin 1.4, Android 11, Android Studio 4.1

Part 1: Preparation & Setup

03. Add Tables to the Database

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 02. Configure SQLDelight Next episode: 04. Instantiate the Database

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Let’s explore how the database of our bug collector app is supposed to work. Afterwards, we will create some tables for it!

CREATE TABLE bug (

);
CREATE TABLE bug (
+   bugId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+   name TEXT NOT NULL,
+   description TEXT
);
CREATE TABLE bugAttributes (
  attributesId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  bugId INTEGER NOT NULL,
  size TEXT NOT NULL,
  weight TEXT NOT NULL,
  attack INTEGER NOT NULL,
  defense INTEGER NOT NULL,

  FOREIGN KEY(bugId)
    REFERENCES bug(bugId)
    ON DELETE CASCADE
);

CREATE TABLE collection (
  collectionId INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  creationTime INTEGER NOT NULL,
  name TEXT NOT NULL
);

CREATE TABLE inCollection (
  collectionId INTEGER NOT NULL,
  bugId INTEGER NOT NULL,
  quantity INTEGER NOT NULL,

  FOREIGN KEY(collectionId)
    REFERENCES collection(collectionId)
    ON DELETE CASCADE,

  FOREIGN KEY(bugId)
    REFERENCES bug(bugId)
    ON DELETE CASCADE
);
Delete com.raywenderlich.android.sqldelight.models.db.PlaceholderModels.kt