<?php
namespace nur\sery\db\_private;

trait Tcreate {
  static function isa(string $sql): bool {
    //return preg_match("/^create(?:\s+table)?\b/i", $sql);
    #XXX implémentation minimale
    return preg_match("/^create\s+table\b/i", $sql);
  }

  static function parse(array $query, ?array &$bindings=null): string {
    #XXX implémentation minimale
    $sql = [self::merge_seq($query)];

    ## préfixe
    if (($prefix = $query["prefix"] ?? null) !== null) $sql[] = $prefix;

    ## table
    $sql[] = $query["table"];

    ## columns
    $cols = $query["cols"];
    $index = 0;
    foreach ($cols as $col => &$definition) {
      if ($col === $index) {
        $index++;
      } else {
        $definition = "$col $definition";
      }
    }; unset($definition);
    $sql[] = "(\n  ".implode("\n, ", $cols)."\n)";

    ## suffixe
    if (($suffix = $query["suffix"] ?? null) !== null) $sql[] = $suffix;

    ## fin de la requête
    return implode(" ", $sql);
  }
}
