Bug 1317841 - Stylistic pass on new kinto-storage-adapter, r?MattN draft
authorEthan Glasser-Camp <eglassercamp@mozilla.com>
Wed, 16 Nov 2016 11:13:32 -0500
changeset 439923 cb82215d41275b220e9a73da4b6a185f0e5ba30b
parent 439922 e56c0659df50911ae2f1e468e172502a527880a2
child 537280 3f37475843cdde199bb4cb2ec30d1b8f7dea375a
push id36125
push usereglassercamp@mozilla.com
push dateWed, 16 Nov 2016 20:26:13 +0000
reviewersMattN
bugs1317841
milestone53.0a1
Bug 1317841 - Stylistic pass on new kinto-storage-adapter, r?MattN - Reflow things to try to avoid long lines. - Add terminal comma where possible. MozReview-Commit-ID: 1USxo0lO33w
services/common/kinto-storage-adapter.js
--- 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);
     });
   }
 }