@@ -29,11 +29,10 @@ export const createTabularSqlitePersister = <ListeningHandle>(
2929 [ valuesLoad , valuesSave , valuesTableName ] ,
3030 ] : DefaultedTabularConfig ,
3131 managedTableNames : string [ ] ,
32+ scheduleId : any ,
3233) : Persister => {
33- const [ refreshSchema , loadTable , saveTable ] = getCommandFunctions (
34- cmd ,
35- managedTableNames ,
36- ) ;
34+ const [ refreshSchema , loadTable , saveTable , transaction ] =
35+ getCommandFunctions ( cmd , managedTableNames , onIgnoredError ) ;
3736
3837 const saveTables = async (
3938 tables :
@@ -109,38 +108,41 @@ export const createTabularSqlitePersister = <ListeningHandle>(
109108 ]
110109 : { } ;
111110
112- const getPersisted = async ( ) : Promise < [ Tables , Values ] | undefined > => {
113- await refreshSchema ( ) ;
114- const tables = await loadTables ( ) ;
115- const values = await loadValues ( ) ;
116- return ! objIsEmpty ( tables ) || ! isUndefined ( values )
117- ? [ tables as Tables , values as Values ]
118- : undefined ;
119- } ;
111+ const getPersisted = async ( ) : Promise < [ Tables , Values ] | undefined > =>
112+ await transaction ( async ( ) => {
113+ await refreshSchema ( ) ;
114+ const tables = await loadTables ( ) ;
115+ const values = await loadValues ( ) ;
116+ return ! objIsEmpty ( tables ) || ! isUndefined ( values )
117+ ? [ tables as Tables , values as Values ]
118+ : undefined ;
119+ } ) ;
120120
121121 const setPersisted = async (
122122 getContent : ( ) => [ Tables , Values ] ,
123123 getTransactionChanges ?: GetTransactionChanges ,
124- ) : Promise < void > => {
125- await refreshSchema ( ) ;
126- if ( ! isUndefined ( getTransactionChanges ) ) {
127- const [ tableChanges , valueChanges ] = getTransactionChanges ( ) ;
128- await saveTables ( tableChanges , true ) ;
129- await saveValues ( valueChanges , true ) ;
130- } else {
131- const [ tables , values ] = getContent ( ) ;
132- await saveTables ( tables ) ;
133- await saveValues ( values ) ;
134- }
135- } ;
124+ ) : Promise < void > =>
125+ await transaction ( async ( ) => {
126+ await refreshSchema ( ) ;
127+ if ( ! isUndefined ( getTransactionChanges ) ) {
128+ const [ tableChanges , valueChanges ] = getTransactionChanges ( ) ;
129+ await saveTables ( tableChanges , true ) ;
130+ await saveValues ( valueChanges , true ) ;
131+ } else {
132+ const [ tables , values ] = getContent ( ) ;
133+ await saveTables ( tables ) ;
134+ await saveValues ( values ) ;
135+ }
136+ } ) ;
136137
137- const persister : any = createCustomPersister (
138+ const persister : any = ( createCustomPersister as any ) (
138139 store ,
139140 getPersisted ,
140141 setPersisted ,
141142 addPersisterListener ,
142143 delPersisterListener ,
143144 onIgnoredError ,
145+ scheduleId ,
144146 ) ;
145147
146148 return persister ;
0 commit comments