Skip to content

Commit

Permalink
autodispose db
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Jan 13, 2024
1 parent 8700c25 commit 8a95ed9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions datastore/sql/sqlitedsdb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ proc getDBFilePath*(path: string): ?!string =
return failure(exc.msg)

proc close*(self: var SQLiteDsDb) =

var
env: AutoDisposed[SQLite]

defer:
disposeIfUnreleased(env)

env.val = self.env

if not RawStmtPtr(self.containsStmt).isNil:
self.containsStmt.dispose

Expand Down Expand Up @@ -316,10 +325,6 @@ proc close*(self: var SQLiteDsDb) =
if not RawStmtPtr(self.getChangesStmt).isNil:
self.getChangesStmt.dispose

if not self.env.isNil:
self.env.dispose
self.env = nil

proc open*(
T: type SQLiteDsDb,
path = Memory,
Expand Down

0 comments on commit 8a95ed9

Please sign in to comment.