Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit b65e21f

Browse files
author
kahverengi
committed
Add getNoteByID method to NoteDao
1 parent ba2e214 commit b65e21f

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/main/kotlin/com/parnote/db/dao/NoteDao.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ interface NoteDao : Dao<Note> {
5252
sqlConnection: SQLConnection,
5353
handler: (exists: Boolean?, asyncResult: AsyncResult<*>) -> Unit
5454
)
55+
56+
fun getNoteByID(
57+
noteID: Int,
58+
sqlConnection: SQLConnection,
59+
handler: (note: Note?, asyncResult: AsyncResult<*>) -> Unit
60+
)
5561
}

src/main/kotlin/com/parnote/db/entity/NoteDaoImpl.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,31 @@ class NoteDaoImpl(override val tableName: String = "note") : DaoImpl(), NoteDao
184184
handler.invoke(null, queryResult)
185185
}
186186
}
187+
188+
override fun getNoteByID(
189+
noteID: Int,
190+
sqlConnection: SQLConnection,
191+
handler: (note: Note?, asyncResult: AsyncResult<*>) -> Unit
192+
) {
193+
val query =
194+
"SELECT `id`, `user_id`, `title`, `text`, `last_modified`, `status`, `favorite` FROM `${getTablePrefix() + tableName}` WHERE `id` = ?"
195+
196+
sqlConnection.queryWithParams(query, JsonArray().add(noteID)) { queryResult ->
197+
if (queryResult.succeeded()) {
198+
val row = queryResult.result().results[0]
199+
val note = Note(
200+
row.getInteger(0),
201+
row.getInteger(1),
202+
row.getString(2),
203+
row.getString(3),
204+
row.getString(4),
205+
row.getInteger(5),
206+
row.getBoolean(6)
207+
)
208+
209+
handler.invoke(note, queryResult)
210+
} else
211+
handler.invoke(null, queryResult)
212+
}
213+
}
187214
}

0 commit comments

Comments
 (0)