braxtonhall / bobs-server

https://bobs-server.net
1 stars 1 forks source link

Abstract away `tx` #50

Closed braxtonhall closed 4 months ago

braxtonhall commented 4 months ago

Before

db // refers to the database outside the transaction

db.$transaction(async (tx) => {
    tx // refers to the transaction
    db // refers to the database outside the transaction -- probably never actually want to use this
})

After

db // refers to the database outside the transaction

transaction(async () => {
    db // refers to the transaction. "other db" is not accessible
});

The nice thing is that you don't need to pass tx through a arguments. It's literally just dynamically scoped.

github-actions[bot] commented 4 months ago
Lines Statements Branches Functions
Coverage: 28%
30.34% (348/1147) 20.07% (51/254) 22.4% (69/308)