<commit_before>module Storage
  class VirtualTableConfigTable < AbstractTable
    def initialize(@manager : Manager)
    end

    def replace(key)
      yield nil
      raise "TODO"
    end

    def scan
      @manager.databases.each_value do |db|
        db.tables.each_value do |table|
          yield ReQL::Datum.new({
            "db"          => db.info.name,
            "durability"  => table.soft_durability ? "soft" : "hard",
            "id"          => table.id.to_s,
            "indexes"     => [] of String,
            "name"        => table.name,
            "primary_key" => table.primary_key,
            "shards"      => [
              {
                "nonvoting_replicas" => [] of String,
                "primary_replica"    => @manager.system_info.name,
                "replicas"           => [@manager.system_info.name],
              },
            ],
            "write_acks" => "single",
            "write_hook" => nil,
          }).hash_value
        end
      end
    end
  end
end<commit_msg>reimplement table_config as child of VirtualTable<commit_after>module Storage
  class VirtualTableConfigTable < VirtualTable
    def initialize(@manager : Manager)
      super("table_config")
    end

    def replace(key)
      yield nil
      raise "TODO"
    end

    private def encode(info : KeyValueStore::TableInfo)
      ReQL::Datum.new({
        "db"          => @manager.kv.get_db(info.db).try &.name || info.db.to_s,
        "durability"  => info.soft_durability ? "soft" : "hard",
        "id"          => info.id.to_s,
        "indexes"     => [] of String,
        "name"        => info.name,
        "primary_key" => info.primary_key,
        "shards"      => [
          {
            "nonvoting_replicas" => [] of String,
            "primary_replica"    => @manager.system_info.name,
            "replicas"           => [@manager.system_info.name],
          },
        ],
        "write_acks" => "single",
        "write_hook" => nil,
      }).hash_value
    end

    def get(key)
      id = UUID.new(key.string_value) rescue return nil
      encode(@manager.kv.get_table(id))
    end

    def scan
      @manager.kv.each_table do |info|
        yield encode(info)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12254025044722719, 'fraction_numerical': 0.0, 'mean_word_length': 1.625586854460094, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '970965', 'n_tokens_mistral': 692, 'n_tokens_neox': 683, 'n_words': 136}