--- a/services/common/kinto-storage-adapter.js
+++ b/services/common/kinto-storage-adapter.js
@@ -167,20 +167,24 @@ const statements = {
AND record_id IN `,
"importData": `
REPLACE INTO collection_data (collection_name, record_id, record)
VALUES (:collection_name, :record_id, :record);`,
"scanAllRecords": `SELECT * FROM collection_data;`,
- "clearCollectionMetadata": `DELETE FROM collection_metadata;`
+ "clearCollectionMetadata": `DELETE FROM collection_metadata;`,
};
-const createStatements = ["createCollectionData", "createCollectionMetadata", "createCollectionDataRecordIdIndex"];
+const createStatements = [
+ "createCollectionData",
+ "createCollectionMetadata",
+ "createCollectionDataRecordIdIndex",
+];
const currentSchemaVersion = 1;
/**
* Firefox adapter.
*
* Uses Sqlite as a backing store.
*
@@ -257,17 +261,20 @@ class FirefoxAdapter extends Kinto.adapt
}
let result;
const conn = this._connection;
const collection = this.collection;
return conn.executeTransaction(function* doExecuteTransaction() {
// Preload specified records from DB, within transaction.
- const parameters = [collection, ...options.preload];
+ const parameters = [
+ collection,
+ ...options.preload,
+ ];
const placeholders = options.preload.map(_ => "?");
const stmt = statements.listRecordsById + "(" + placeholders.join(",") + ");";
const rows = yield conn.execute(stmt, parameters);
const preloaded = rows.reduce((acc, row) => {
const record = JSON.parse(row.getResultByName("record"));
acc[row.getResultByName("record_id")] = record;
return acc;
@@ -280,29 +287,29 @@ class FirefoxAdapter extends Kinto.adapt
yield conn.executeCached(statement, params);
}
}, conn.TRANSACTION_EXCLUSIVE).then(_ => result);
}
get(id) {
const params = {
collection_name: this.collection,
- record_id: id
+ record_id: id,
};
return this._executeStatement(statements.getRecord, params).then(result => {
if (result.length == 0) {
return;
}
return JSON.parse(result[0].getResultByName("record"));
});
}
list(params = { filters: {}, order: "" }) {
const parameters = {
- collection_name: this.collection
+ collection_name: this.collection,
};
return this._executeStatement(statements.listRecords, parameters).then(result => {
const records = [];
for (let k = 0; k < result.length; k++) {
const row = result[k];
records.push(JSON.parse(row.getResultByName("record")));
}
return records;
@@ -327,58 +334,63 @@ class FirefoxAdapter extends Kinto.adapt
const connection = this._connection;
const collection_name = this.collection;
return Task.spawn(function* () {
yield connection.executeTransaction(function* doImport() {
for (let record of records) {
const params = {
collection_name: collection_name,
record_id: record.id,
- record: JSON.stringify(record)
+ record: JSON.stringify(record),
};
yield connection.execute(statements.importData, params);
}
const lastModified = Math.max(...records.map(record => record.last_modified));
const params = {
- collection_name: collection_name
+ collection_name: collection_name,
};
- const previousLastModified = yield connection.execute(statements.getLastModified, params).then(result => {
- return result.length > 0 ? result[0].getResultByName("last_modified") : -1;
- });
+ const previousLastModified = yield connection.execute(
+ statements.getLastModified, params).then(result => {
+ return result.length > 0
+ ? result[0].getResultByName("last_modified")
+ : -1;
+ });
if (lastModified > previousLastModified) {
const params = {
collection_name: collection_name,
- last_modified: lastModified
+ last_modified: lastModified,
};
yield connection.execute(statements.saveLastModified, params);
}
});
return records;
});
}
saveLastModified(lastModified) {
const parsedLastModified = parseInt(lastModified, 10) || null;
const params = {
collection_name: this.collection,
- last_modified: parsedLastModified
+ last_modified: parsedLastModified,
};
- return this._executeStatement(statements.saveLastModified, params).then(() => parsedLastModified);
+ return this._executeStatement(statements.saveLastModified, params)
+ .then(() => parsedLastModified);
}
getLastModified() {
const params = {
- collection_name: this.collection
+ collection_name: this.collection,
};
- return this._executeStatement(statements.getLastModified, params).then(result => {
- if (result.length == 0) {
- return 0;
- }
- return result[0].getResultByName("last_modified");
- });
+ return this._executeStatement(statements.getLastModified, params)
+ .then(result => {
+ if (result.length == 0) {
+ return 0;
+ }
+ return result[0].getResultByName("last_modified");
+ });
}
/**
* Reset the sync status of every record and collection we have
* access to.
*/
resetSyncStatus() {
// We're going to use execute instead of executeCached, so build
@@ -395,19 +407,23 @@ class FirefoxAdapter extends Kinto.adapt
const collection_name = row.getResultByName("collection_name");
if (record._status === "deleted") {
// Garbage collect deleted records.
promises.push(conn.execute(statements.deleteData, { collection_name, record_id }));
}
else {
const newRecord = Object.assign({}, record, {
_status: "created",
- last_modified: undefined
+ last_modified: undefined,
});
- promises.push(conn.execute(statements.updateData, { record: JSON.stringify(newRecord), record_id, collection_name }));
+ promises.push(conn.execute(statements.updateData, {
+ record: JSON.stringify(newRecord),
+ record_id,
+ collection_name,
+ }));
}
});
yield Promise.all(promises);
yield conn.execute(statements.clearCollectionMetadata);
});
}
}