From the course: Advanced Kotlin Database Development
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Inserting a new entry - Kotlin Tutorial
From the course: Advanced Kotlin Database Development
Inserting a new entry
- [Instructor] Now, when we have created our table, let's add some rows to it. I moved the connection and the creation of the tables into separate functions so we can focus on task at hand. To insert a new row, we start with our table object, and we invoke insert function on it. This function receives a block with a single parameter. Let's give it a name so it will be easier to reference from now on. Let's call it row. Since our table was defined as int ID table, the ID column will be set and auto-incremented automatically. We only need to worry about setting the other columns. To assign value to the name column, we reference it using square brackets. So we'll say "row," and then we'll say "name." And let's give it some value. You can think about that as assigning values to regular a Kotlin map, where keys are the columns that you have. Since Kotlin is a type-safe language, you'll also get auto-completion. And if you…
Contents
-
-
-
Connecting to your database5m 2s
-
(Locked)
Opening a transaction1m 47s
-
(Locked)
Using data types3m 28s
-
(Locked)
Creating and dropping tables3m 50s
-
(Locked)
Inserting a new entry2m 37s
-
(Locked)
Querying all entries1m 10s
-
(Locked)
Querying a single entry2m 42s
-
(Locked)
Updating an entry3m 18s
-
(Locked)
Deleting entries1m 20s
-
(Locked)
Challenge: Create and populate a second table40s
-
(Locked)
Solution: Create and populate a second table3m 3s
-
-
-
-