@@ -84,13 +84,13 @@ class IdbDatastore extends Adapter {
84
84
tx . onabort = cleanup
85
85
86
86
this . _tx = {
87
- tx ,
87
+ store : tx . store ,
88
88
done
89
89
}
90
90
}
91
91
92
92
// we only operate on one object store so the tx.store property is set
93
- return this . _tx . tx . store
93
+ return this . _tx . store
94
94
}
95
95
96
96
async * _queryIt ( q ) {
@@ -146,7 +146,11 @@ class IdbDatastore extends Adapter {
146
146
147
147
async put ( key , val ) {
148
148
try {
149
- await this . _getStore ( ) . put ( val , key . toBuffer ( ) )
149
+ if ( this . _tx ) {
150
+ await this . _tx . store . put ( val , key . toBuffer ( ) )
151
+ } else {
152
+ await this . store . put ( this . location , val , key . toBuffer ( ) )
153
+ }
150
154
} catch ( err ) {
151
155
throw Errors . dbWriteFailedError ( err )
152
156
}
@@ -155,7 +159,11 @@ class IdbDatastore extends Adapter {
155
159
async get ( key ) {
156
160
let value
157
161
try {
158
- value = await this . _getStore ( ) . get ( key . toBuffer ( ) )
162
+ if ( this . _tx ) {
163
+ value = await this . _tx . store . get ( key . toBuffer ( ) )
164
+ } else {
165
+ value = await this . store . get ( this . location , key . toBuffer ( ) )
166
+ }
159
167
} catch ( err ) {
160
168
throw Errors . dbWriteFailedError ( err )
161
169
}
@@ -169,7 +177,13 @@ class IdbDatastore extends Adapter {
169
177
170
178
async has ( key ) {
171
179
try {
172
- const res = await this . _getStore ( ) . getKey ( key . toBuffer ( ) )
180
+ let res
181
+
182
+ if ( this . _tx ) {
183
+ res = await this . _tx . store . getKey ( key . toBuffer ( ) )
184
+ } else {
185
+ res = await this . store . getKey ( this . location , key . toBuffer ( ) )
186
+ }
173
187
174
188
return Boolean ( res )
175
189
} catch ( err ) {
@@ -180,7 +194,11 @@ class IdbDatastore extends Adapter {
180
194
181
195
async delete ( key ) {
182
196
try {
183
- await this . _getStore ( ) . delete ( key . toBuffer ( ) )
197
+ if ( this . _tx ) {
198
+ await this . _tx . store . delete ( key . toBuffer ( ) )
199
+ } else {
200
+ await this . store . delete ( this . location , key . toBuffer ( ) )
201
+ }
184
202
} catch ( err ) {
185
203
throw Errors . dbDeleteFailedError ( err )
186
204
}
0 commit comments