Add simple db transaction controller
This commit is contained in:
@@ -1,3 +1,30 @@
|
||||
import Database from 'tauri-plugin-sql-api'
|
||||
import { dbStateStore } from '$lib/store/dbState'
|
||||
|
||||
export const db = await Database.load('sqlite:food.db')
|
||||
|
||||
const DBService = {
|
||||
Begin() {
|
||||
dbStateStore.update((state) => {
|
||||
state.transacting = true
|
||||
return state
|
||||
})
|
||||
return db.execute('begin transaction')
|
||||
},
|
||||
Commit() {
|
||||
dbStateStore.update((state) => {
|
||||
state.transacting = false
|
||||
return state
|
||||
})
|
||||
return db.execute('commit')
|
||||
},
|
||||
Rollback() {
|
||||
dbStateStore.update((state) => {
|
||||
state.transacting = false
|
||||
return state
|
||||
})
|
||||
return db.execute('rollback')
|
||||
}
|
||||
}
|
||||
|
||||
export { DBService }
|
||||
|
||||
Reference in New Issue
Block a user