db, json, time, term: change optional to result (#16201)

This commit is contained in:
yuyi 2022-10-26 16:26:28 +08:00 committed by GitHub
parent 2a7420f572
commit 992b502198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 340 additions and 340 deletions

View file

@ -106,7 +106,7 @@ fn C.sqlite3_errmsg(&C.sqlite3) &char
fn C.sqlite3_free(voidptr)
// connect Opens the connection with a database.
pub fn connect(path string) ?DB {
pub fn connect(path string) !DB {
db := &C.sqlite3(0)
code := C.sqlite3_open(&char(path.str), &db)
if code != 0 {
@ -124,7 +124,7 @@ pub fn connect(path string) ?DB {
// close Closes the DB.
// TODO: For all functions, determine whether the connection is
// closed first, and determine what to do if it is
pub fn (mut db DB) close() ?bool {
pub fn (mut db DB) close() !bool {
code := C.sqlite3_close(db.conn)
if code == 0 {
db.is_open = false
@ -217,7 +217,7 @@ pub fn (db &DB) exec(query string) ([]Row, int) {
// Execute a query, handle error code
// Return the first row from the resulting table
[manualfree]
pub fn (db &DB) exec_one(query string) ?Row {
pub fn (db &DB) exec_one(query string) !Row {
rows, code := db.exec(query)
defer {
unsafe { rows.free() }