<commit_before>const DB = require('./index');

var Note = function(attrs) {
    this.id = attrs.id;
    this.name = attrs.name;
    this.content = attrs.content;
    this.folderId = attrs.folderid;
    this.createdAt = attrs.createdat;
    this.updatedAt = attrs.updatedat;

    this.delete = () => {
      const db = DB.con();
      return db.query(`delete from notes where id = ${this.id}`)
        .then((res) => {
          db.end();
        });
    }

    this.save = () => {
      const db = DB.con();
      const query = {
        text: `update notes set name = $1, content = $2, folderid = $3, updatedat = $4 where id = $5;`,
        values: [this.name, this.content, this.folderId, this.updatedAt, this.id]
      }

      return db.query(query)
        .then((res) => {
          db.end();
          return this;
        })
        .catch(e => console.error(e.stack));
    }
}

module.exports = () => {
  return {
    note: Note,

    create: (attrs) => {
      const query = {
        text: `INSERT INTO notes (name, content, folderid, createdAt, updatedAt) values ($1, $2, $3, $4, $5) RETURNING *;`,
        values: [
          attrs.name,
          attrs.content,
          attrs.folderId,
          new Date(),
          new Date(),
        ]
      }
      const db = DB.con();

      return db.query(query)
        .then((res) => {
          const note = new Note(res.rows[0]);
          db.end();
          return note;
        })
        .catch(e => console.error(e.stack));
    },

    findById: (id) => {
      const query = {
        text: `select * from notes where id = $1;`,
        values: [id]
      }
      const db = DB.con();

      return db.query(query)
        .then((res) => {
          const note = new Note(res.rows[0]);
          db.end();
          return note;
        })
        .catch(e => console.error(e.stack));
    },

    findAll: () => {
      const db = DB.con();

      return db.query(`select * from notes;`)
        .then((res) => {
          db.end();

          // Add the save and delete methods.
          const notes = [];
          res.rows.forEach((row) => {
            notes.push(new Note(row));
          });

          return notes;
        })
        .catch(e => console.error(e.stack));
    },
  }
}
<commit_msg>Added 'order by updated at desc' to Note.findAll.<commit_after>const DB = require('./index');

var Note = function(attrs) {
    this.id = attrs.id;
    this.name = attrs.name;
    this.content = attrs.content;
    this.folderId = attrs.folderid;
    this.createdAt = attrs.createdat;
    this.updatedAt = attrs.updatedat;

    this.delete = () => {
      const db = DB.con();
      return db.query(`delete from notes where id = ${this.id}`)
        .then((res) => {
          db.end();
        });
    }

    this.save = () => {
      const db = DB.con();
      const query = {
        text: `update notes set name = $1, content = $2, folderid = $3, updatedat = $4 where id = $5;`,
        values: [this.name, this.content, this.folderId, new Date(), this.id]
      }

      return db.query(query)
        .then((res) => {
          db.end();
          return this;
        })
        .catch(e => console.error(e.stack));
    }
}

module.exports = () => {
  return {
    note: Note,

    create: (attrs) => {
      const query = {
        text: `INSERT INTO notes (name, content, folderid, createdAt, updatedAt) values ($1, $2, $3, $4, $5) RETURNING *;`,
        values: [
          attrs.name,
          attrs.content,
          attrs.folderId,
          new Date(),
          new Date(),
        ]
      }
      const db = DB.con();

      return db.query(query)
        .then((res) => {
          const note = new Note(res.rows[0]);
          db.end();
          return note;
        })
        .catch(e => console.error(e.stack));
    },

    findById: (id) => {
      const query = {
        text: `select * from notes where id = $1;`,
        values: [id]
      }
      const db = DB.con();

      return db.query(query)
        .then((res) => {
          const note = new Note(res.rows[0]);
          db.end();
          return note;
        })
        .catch(e => console.error(e.stack));
    },

    findAll: () => {
      const db = DB.con();

      return db.query(`select * from notes order by updatedat desc;`)
        .then((res) => {
          db.end();

          // Add the save and delete methods.
          const notes = [];
          res.rows.forEach((row) => {
            notes.push(new Note(row));
          });

          return notes;
        })
        .catch(e => console.error(e.stack));
    },
  }
}

{'fraction_non_alphanumeric': 0.1657974793568014, 'fraction_numerical': 0.005649717514124294, 'mean_word_length': 1.5859550561797753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2918157', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1459, 'n_words': 344}