Insert 插入
方式一、构造OQL语句
@Test
fun testInsertOQL() {
val book2 = TestBook()
book2.testName = "abcInsertOQL"
book2.testURL = "InsertOQL"
val q = OQL.From(book2).Insert(book2.testName, book2.testURL).END
val rowsInserted = getDB().insert(q)
Assert.assertTrue(rowsInserted > 0)
}
|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| finalSql | INSERT INTO `test_book` |
| | |
| | (`test_name`,`test_url`,`created_at`,`updated_at`,`created_by`,`updated_by`,`test_id`) |
| | |
| | Values |
| | |
| | ('abcInsertOQL','InsertOQL','2017-05-17T20:48:52.428','2017-05-17T20:48:52.428','zhangsanfeng','zhangsanfeng','17170652179681280') |
|---------------------------------------------------------------------------------------------------------------------------------------------------------|
方式二、直接操作Entity
@Test
fun insertEntity() {
val tb = TestBook()
tb.testName = "test"
val rowsInserted = getDB().insert(tb)
Assert.assertTrue(rowsInserted > 0)
}
|------------------------------------------------------------------------------------------------------------------------------------|
| finalSql | INSERT INTO `test_book` |
| | |
| | (`created_at`,`updated_at`,`created_by`,`updated_by`,`test_name`,`test_id`) |
| | |
| | Values |
| | |
| | ('2017-05-17T20:47:56.786','2017-05-17T20:47:56.786','zhangsanfeng','zhangsanfeng','test','17170415822262272') |
|------------------------------------------------------------------------------------------------------------------------------------