Testing CouchDB sync.

This commit is contained in:
Eric van der Vlist 2022-12-23 15:41:03 +01:00
parent 30a7bdfd12
commit 55164ef2a3
2 changed files with 38 additions and 4 deletions

View File

@ -373,16 +373,17 @@ export const getGpx = async (params: any) => {
gpx = row.doc.doc;
}
//level 1 (extensions)
if (row.doc.type === 'extensions') {
if (target !== undefined && row.doc.type === 'extensions') {
target.splice(1);
appendToArray(target.at(-1), row.doc.type, row.doc.doc);
target.push(row.doc.doc);
}
//level 1 (others)
if (
row.doc.type === 'wpt' ||
row.doc.type === 'rte' ||
row.doc.type === 'trk'
target !== undefined &&
(row.doc.type === 'wpt' ||
row.doc.type === 'rte' ||
row.doc.type === 'trk')
) {
target.splice(1);
appendToArray(target.at(-1), row.doc.type, row.doc._id);

View File

@ -51,6 +51,39 @@ export const initDb = async (params: any) => {
globalThis.dbReady = true;
const sync = PouchDB.sync(
'dyomedea',
'http://admin:password@localhost:5984/dyomedea',
{
live: true,
retry: true,
}
)
.on('change', function (info) {
// handle change
console.log({ caller: 'Sync / change', info });
})
.on('paused', function (err) {
// replication paused (e.g. replication up to date, user went offline)
console.log({ caller: 'Sync / paused', err });
})
.on('active', function () {
// replicate resumed (e.g. new changes replicating, user went back online)
console.log({ caller: 'Sync / active' });
})
.on('denied', function (err) {
// a document failed to replicate (e.g. due to permissions)
console.error({ caller: 'Sync / denied', err });
})
.on('complete', function (info) {
// handle complete
console.log({ caller: 'Sync / complete', info });
})
.on('error', function (err) {
// handle error
console.error({ caller: 'Sync / error', err });
});
console.log({ caller: 'initDb / before db.changes' });
const changes = db