mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor(sqlite): Removed db_ prefix from db_open and db_close.
This commit is contained in:
4
TODOS.md
4
TODOS.md
@@ -48,6 +48,10 @@
|
||||
|
||||
26. Test all cmds / terminal branches.
|
||||
|
||||
27. Replace `fmt.tprintf("/tmp/envr-test-...-%d", os.get_pid())` + `os.mkdir_all` in test files with `os.mkdir_temp` (race-free, honors `$TMPDIR`, matches `findr/test_env.odin` pattern).
|
||||
|
||||
28. Adopt `core:log` across `db.odin`, `crypto.odin`, `config.odin`, `ssh.odin` — replace ~30 scattered `fmt.printf("Error ...")` calls with leveled logging for consistent stderr routing and source locations.
|
||||
|
||||
## Double-check AI output
|
||||
|
||||
- [ ] cli.odin
|
||||
|
||||
8
db.odin
8
db.odin
@@ -65,7 +65,7 @@ db_open :: proc(cfg_path: string) -> (database: Db, ok: bool) {
|
||||
data_path := data_path(database.cfg.config_path, context.temp_allocator)
|
||||
if os.exists(data_path) {
|
||||
if ok = db_restore_from_encrypted(&database, data_path); !ok {
|
||||
sqlite.db_close(database.db)
|
||||
sqlite.close(database.db)
|
||||
return database, false
|
||||
}
|
||||
} else {
|
||||
@@ -80,7 +80,7 @@ db_open :: proc(cfg_path: string) -> (database: Db, ok: bool) {
|
||||
// In production, you most likely want to use `db_open`.
|
||||
db_init :: proc() -> (database: Db, ok: bool) {
|
||||
db: ^rawptr
|
||||
rc := sqlite.db_open(":memory:", &db)
|
||||
rc := sqlite.open(":memory:", &db)
|
||||
if rc != sqlite.OK {
|
||||
fmt.printf("Error opening in-memory database: %s\n", sqlite.db_errmsg(db))
|
||||
return
|
||||
@@ -90,7 +90,7 @@ db_init :: proc() -> (database: Db, ok: bool) {
|
||||
rc = sqlite.db_exec(db, create_sql, nil, nil, nil)
|
||||
if rc != sqlite.OK {
|
||||
fmt.printf("Error creating table: %s\n", sqlite.db_errmsg(db))
|
||||
sqlite.db_close(db)
|
||||
sqlite.close(db)
|
||||
return
|
||||
}
|
||||
database.db = db
|
||||
@@ -148,7 +148,7 @@ db_close :: proc(d: ^Db) {
|
||||
allocator := db_allocator(d)
|
||||
|
||||
defer {
|
||||
sqlite.db_close(d.db)
|
||||
sqlite.close(d.db)
|
||||
|
||||
delete_config(&d.cfg, allocator)
|
||||
|
||||
|
||||
@@ -166,12 +166,12 @@ test_decrypt_then_deserialize_sqlite :: proc(t: ^testing.T) {
|
||||
defer delete(plaintext)
|
||||
|
||||
mem_db: ^rawptr
|
||||
rc := sqlite.db_open(":memory:", &mem_db)
|
||||
rc := sqlite.open(":memory:", &mem_db)
|
||||
testing.expectf(t, rc == sqlite.OK, "failed to open in-memory db")
|
||||
if rc != sqlite.OK {
|
||||
return
|
||||
}
|
||||
defer sqlite.db_close(mem_db)
|
||||
defer sqlite.close(mem_db)
|
||||
|
||||
n := i64(len(plaintext))
|
||||
buf := sqlite.malloc64(n)
|
||||
|
||||
@@ -13,9 +13,9 @@ DESERIALIZE_RESIZEABLE :: 2
|
||||
|
||||
foreign lib {
|
||||
@(link_name = "sqlite3_open")
|
||||
db_open :: proc(filename: cstring, ppDb: ^^rawptr) -> c.int ---
|
||||
open :: proc(filename: cstring, ppDb: ^^rawptr) -> c.int ---
|
||||
@(link_name = "sqlite3_close")
|
||||
db_close :: proc(db: ^rawptr) -> c.int ---
|
||||
close :: proc(db: ^rawptr) -> c.int ---
|
||||
@(link_name = "sqlite3_errmsg")
|
||||
db_errmsg :: proc(db: ^rawptr) -> cstring ---
|
||||
@(link_name = "sqlite3_exec")
|
||||
@@ -43,3 +43,4 @@ foreign lib {
|
||||
@(link_name = "sqlite3_free")
|
||||
free :: proc(p: rawptr) ---
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user