fun main()

in documentation-website/Writerside/snippets/get-started-with-exposed-dao/src/main/kotlin/org/example/App.kt [8:43]


fun main() {
    Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver")

    transaction {
        addLogger(StdOutSqlLogger)

        // ...

        SchemaUtils.create(Tasks)

        val task1 = Task.new {
            title = "Learn Exposed DAO"
            description = "Follow the DAO tutorial"
        }

        val task2 = Task.new {
            title = "Read The Hobbit"
            description = "Read chapter one"
            isCompleted = true
        }

        println("Created new tasks with ids ${task1.id} and ${task2.id}")

        val completed = Task.find { Tasks.isCompleted eq true }.toList()
        println("Completed tasks: ${completed.count()}")

        // Update
        task1.title = "Try Exposed DAO"
        task1.isCompleted = true
        println("Updated task1: $task1")

        // Delete
        task2.delete()
        println("Remaining tasks: ${Task.all().toList()}")
    }
}