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

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