<commit_before><?php

namespace Core;

class Table
{

  static $primary;

  static $classname;

  static $tablename;

  static $unique_indexes = [];

  static function get($id)
  {
    if (static::$primary) {
      return static::get_one(static::$primary, $id);
    }
  }

  static function get_one($key, $value)
  {
    // From Cache
    $use_cache = in_array($key, static::$unique_indexes);
    $cache_key = static::$tablename . "_one_" . $key . "_" . $value;
    if ($use_cache && $ressource = cache_get($cache_key)) {
      return $ressource;
    }
    // From DB
    if ($row = db_get_one(static::$tablename, [$key => $value])) {
      $ressource = new static::$classname($row);
      // Set Cache
      if ($use_cache) {
        cache_set($cache_key, $ressource);
      }
      return $ressource;
    }
  }

  static function create($values = [])
  {
    $result = db_insert(static::$tablename, $values);
    if (static::$primary && $id = db_insert_id()) {
      $values[static::$primary] = $id;
    }
    return new static::$classname($values);
  }

  static function delete($where = [])
  {
    return db_delete(static::$tablename, $where);
  }

}
<commit_msg>return canonicalised resource when creating<commit_after><?php

namespace Core;

class Table
{

  static $primary;

  static $classname;

  static $tablename;

  static $unique_indexes = [];

  static function get($id)
  {
    if (static::$primary) {
      return static::get_one(static::$primary, $id);
    }
  }

  static function get_one($key, $value)
  {
    // From Cache
    $use_cache = in_array($key, static::$unique_indexes);
    $cache_key = static::$tablename . "_one_" . $key . "_" . $value;
    if ($use_cache && $ressource = cache_get($cache_key)) {
      return $ressource;
    }
    // From DB
    if ($row = db_get_one(static::$tablename, [$key => $value])) {
      $ressource = new static::$classname($row);
      // Set Cache
      if ($use_cache) {
        cache_set($cache_key, $ressource);
      }
      return $ressource;
    }
  }

  static function create($values = [])
  {
    $result = db_insert(static::$tablename, $values);
    if (static::$primary && $id = db_insert_id()) {
      return static::get($id);
    }
    return new static::$classname($values);
  }

  static function delete($where = [])
  {
    return db_delete(static::$tablename, $where);
  }

}

{'fraction_non_alphanumeric': 0.16581849024597117, 'fraction_numerical': 0.0, 'mean_word_length': 2.9847972972972974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2173534', 'n_tokens_mistral': 810, 'n_tokens_neox': 812, 'n_words': 164}