<commit_before>#!/bin/bash

[[ -z "$BALLS_DB_CREDENTIALS" ]] && BALLS_DB_CREDENTIALS=''
[[ -z "$BALLS_DB" ]] && BALLS_DB='balls'

balls::model::impl() {
  local model="$1"; shift

  local mode="$1"; shift

  if exists "$model.$mode"; then
    "$model.$mode" "$@"
  elif exists "balls::model.$mode"; then
    "balls::model.$mode" "$@"
  else
    stderr "oh no! couldn't find \`$model.$mode\`."
  fi
}

balls::model() {
  alias "$1"="balls::model::impl $1"
}

balls::model.find() {
  mysql $BALLS_DB_CREDENTIALS "$BALLS_DB" -e "SELECT * from $(balls::model.table_name) WHERE $@" | cat
}

balls::model.table_name() {
  local table_name_var="${model}_table_name"
  if [[ -n "$1" ]]; then
    export "$table_name_var"="$1"
  elif [[ -n "${!table_name_var}" ]]; then
    echo "${!table_name_var}"
  else
    echo "$model" | tr '[A-Z]' '[a-z]'
  fi
}<commit_msg>factor out balls::model.execute()<commit_after>#!/bin/bash

[[ -z "$BALLS_DB_CREDENTIALS" ]] && BALLS_DB_CREDENTIALS=''
[[ -z "$BALLS_DB" ]] && BALLS_DB='balls'

balls::model::impl() {
  local model="$1"; shift

  local mode="$1"; shift

  if exists "$model.$mode"; then
    "$model.$mode" "$@"
  elif exists "balls::model.$mode"; then
    "balls::model.$mode" "$@"
  else
    stderr "oh no! couldn't find \`$model.$mode\`."
  fi
}

balls::model() {
  alias "$1"="balls::model::impl $1"
}

balls::model.find() {
  balls::model.execute "SELECT * from $(balls::model.table_name) WHERE $@"
}

balls::model.table_name() {
  local table_name_var="${model}_table_name"
  if [[ -n "$1" ]]; then
    export "$table_name_var"="$1"
  elif [[ -n "${!table_name_var}" ]]; then
    echo "${!table_name_var}"
  else
    echo "$model" | tr '[A-Z]' '[a-z]'
  fi
}

balls::model.execute() {
  mysql $BALLS_DB_CREDENTIALS "$BALLS_DB" -e "$@" | cat
}
{'fraction_non_alphanumeric': 0.23124300111982082, 'fraction_numerical': 0.006718924972004479, 'mean_word_length': 4.105714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7166798', 'n_tokens_mistral': 754, 'n_tokens_neox': 712, 'n_words': 140}