<commit_before>const PostgREST = require('postgrest-client')
const keys = require('lodash/keys')

const postgrestHost = process.env.POSTGREST_HOST
const db = new PostgREST(postgrestHost)

module.exports = {
  getTables () {
    return db.get('/')
      .set('Accept', '*/*') // https://github.com/begriffs/postgrest/issues/860
      .then((data) => {
        return keys(data.definitions)
          .filter((table) => !table.startsWith('(rpc)'))
          .map((table) => ({name: table}))
      })
  },

  getRows (table, limit = 0, offset = 0) {
    const from = offset
    const to = offset + limit
    return db.get(`/${table}`)
      .range(from, to)
      .order('id', true) // ascending
      .set('Accept', '*/*') // https://github.com/begriffs/postgrest/issues/860
  },

  getSchema (table) {
    return db.post('/rpc/get_schema')
      .send({ table_name_param: table })
      .set('Accept', '*/*') // https://github.com/begriffs/postgrest/issues/860
  },

  update (table, updates, conditions) {
    return db.patch(`/${table}`)
      .set('Prefer', 'return=representation') // include row in response
      .set('Accept', 'application/vnd.pgrst.object+json') // return obj not array
      .match(conditions)
      .send(updates)
  },

  deleteRow (table, conditions) {
    return db.delete(`/${table}`)
      .match(conditions)
  },

  renameField (table, oldValue, value) {
    return db.post('/rpc/rename_column')<commit_msg>sort rows by first column instead of id explicitly<commit_after>const PostgREST = require('postgrest-client')
const keys = require('lodash/keys')

const postgrestHost = process.env.POSTGREST_HOST
const db = new PostgREST(postgrestHost)

module.exports = {
  getTables () {
    return db.get('/')
      .set('Accept', '*/*') // https://github.com/begriffs/postgrest/issues/860
      .then((data) => {
        return keys(data.definitions)
          .filter((table) => !table.startsWith('(rpc)'))
          .map((table) => ({name: table}))
      })
  },

  getRows (table, limit = 0, offset = 0) {
    const from = offset
    const to = offset + limit
    return db.get(`/${table}`)
      .range(from, to)
      .order('`1`', true) // first column ascending
      .set('Accept', '*/*') // https://github.com/begriffs/postgrest/issues/860
  },

  getSchema (table) {
    return db.post('/rpc/get_schema')
      .send({ table_name_param: table })
      .set('Accept', '*/*') // https://github.com/begriffs/postgrest/issues/860
  },

  update (table, updates, conditions) {
    return db.patch(`/${table}`)
      .set('Prefer', 'return=representation') // include row in response
      .set('Accept', 'application/vnd.pgrst.object+json') // return obj not array
      .match(conditions)
      .send(updates)
  },

  deleteRow (table, conditions) {
    return db.delete(`/${table}`)
      .match(conditions)
  },

  renameField (table, oldValue, value) {
    return db.post('/rpc/rename_column')
{'fraction_non_alphanumeric': 0.1817560642295866, 'fraction_numerical': 0.007857874957294158, 'mean_word_length': 2.9196787148594376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 6, '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': '7566087', 'n_tokens_mistral': 997, 'n_tokens_neox': 954, 'n_words': 189}