<commit_before>import _ from 'lodash';
import knex from 'knex';
import {
  Store,
} from '../../mariner';

export default class sqlStore extends Store {
  static client;

  constructor(options) {
    super(...arguments);

    this.options = {
      ...options,
    };

    if (options.isBackend) {
      this.tableName = options.tableName || 'migrations';
      this.listItems = null;
    }
  }

  init() {
    const client = this.getClient();

    return this.options.isBackend ? (
      client.schema.hasTable(this.tableName)
      .then((exists) => {
        return exists ? null : client.schema.createTable(this.tableName, (table) => {
          table.increments('id').primary();
          table.string('name').unique().notNullable();
          table.dateTime('migration_time').notNullable();
        });
      })
    ) : null;
  }

  getClient() {
    return sqlStore.client ? sqlStore.client : knex(this.options);
  }

  execute(query, bindings = []) {
    const client = this.getClient();

    return client.raw(query, bindings);
  }

  record(name) {
    const client = this.getClient();

    return client(this.tableName).insert({
      name,
    });
  }

  delete(name) {
    const client = this.getClient();

    return client(this.tableName).delete()
    .where('name', name);
  }

  list() {
    const client = this.getClient();

    return client(this.tableName).select('name')
    .orderBy('name')
    .then((result) => {
      return _.map(result, 'name');
    });
  }
}<commit_msg>sql: include time (not null) when recording<commit_after>import _ from 'lodash';
import knex from 'knex';
import {
  Store,
} from '../../mariner';

export default class sqlStore extends Store {
  static client;

  constructor(options) {
    super(...arguments);

    this.options = {
      ...options,
    };

    if (options.isBackend) {
      this.tableName = options.tableName || 'migrations';
      this.listItems = null;
    }
  }

  init() {
    const client = this.getClient();

    return this.options.isBackend ? (
      client.schema.hasTable(this.tableName)
      .then((exists) => {
        return exists ? null : client.schema.createTable(this.tableName, (table) => {
          table.increments('id').primary();
          table.string('name').unique().notNullable();
          table.dateTime('migration_time').notNullable();
        });
      })
    ) : null;
  }

  getClient() {
    return sqlStore.client ? sqlStore.client : knex(this.options);
  }

  execute(query, bindings = []) {
    const client = this.getClient();

    return client.raw(query, bindings);
  }

  record(name) {
    const client = this.getClient();

    return client(this.tableName).insert({
      name,
      migration_time : new Date(),
    });
  }

  delete(name) {
    const client = this.getClient();

    return client(this.tableName).delete()
    .where('name', name);
  }

  list() {
    const client = this.getClient();

    return client(this.tableName).select('name')
    .orderBy('name')
    .then((result) => {
      return _.map(result, 'name');
    });
  }
}
{'fraction_non_alphanumeric': 0.16171185886965045, 'fraction_numerical': 0.0, 'mean_word_length': 2.58968347010551, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6167430', 'n_tokens_mistral': 973, 'n_tokens_neox': 944, 'n_words': 181}