A set of simple utilities useful for admin work on CrateDB tables.
This is a work in progress so test carefully before using in production!
config.php
define('CRATE_DSN', 'crate:crate1.web64.io:4200');<?php
require "config.php";
require "vendor/autoload.php";
$crate = new Web64\CrateAdmin\Cratedb( CRATE_DSN );Run any query
$resul = $crate->query($sql, $fields = null);Get Crate timestamp from php date string
$crate->ts( $str );Get array of ids from array of rows
$ids = $create->get_ids($item_a, $id_field);Get array of tables in database
$crate->get_tables( $include_system_tables = false )SHOW CREATE TABLE
$sql = $crate->show_create_table('tableName');Get array of field names in table (requires at least 1 record)
$crate->get_table_fields('tableName');Checks if table has data/rows:
if ($crate->has_rows('tableName')){
//...
}Copy all data
$crate->copy($from_table, $to_table);Swap Table (ALTER CLUSTER SWAP TABLE $from_table TO $to_table)
$crate->swap_table($from_table, $to_table)Refresh Table
$crate->refresh_table($table)Drop Table
$crate->drop_table($table)Create a temporary table
$crate->create_temp_table('old_table', 'temp_table');