// https://clickhouse.yandex/docs/en/query_language/create/ #region Create Table public static string CreateTable(string table, string columnsWithType, ITableEngine engine, string db = null, string indexes = null , bool temporary = false, bool ifNotExists = false, string cluster = null) { #region Guard if (string.IsNullOrWhiteSpace(table)) { throw new ArgumentNullException(nameof(table)); } if (string.IsNullOrWhiteSpace(columnsWithType)) { throw new ArgumentNullException(nameof(columnsWithType)); } if (engine == null) { throw new ArgumentNullException(nameof(engine)); } if (db == null && !temporary) { throw new ArgumentNullException(nameof(db)); } #endregion if (temporary) { db = null; } string cmdText = $"CREATE {(temporary ? "TEMPORARY " : "")}TABLE {(ifNotExists ? "IF NOT EXISTS " : "")}" + $"{(!string.IsNullOrWhiteSpace(db) && !temporary ? db + "." : "")}{table}" + $"{(!string.IsNullOrWhiteSpace(cluster) ? " ON CLUSTER " + cluster : "")}" + $"({columnsWithType}{(!string.IsNullOrWhiteSpace(indexes) ? ", " + indexes : "")}) ENGINE = {engine.Text}"; return(cmdText); }
public ClickHouseView(string viewName, ClickHouseTable table, bool addJoinsByReferences = false , ITableEngine engine = null, bool hideForeignKeys = false) { Table = table; ViewName = viewName; CommandText = new ViewCommandText(viewName, table, addJoinsByReferences: addJoinsByReferences , engine: engine, hideForeignKeys: hideForeignKeys); }
//public static string CreateTable(ClickHouseTable table, bool temporary = false, bool ifNotExists = false) => // CreateTable(table: table.Name, columnsWithType: string.Join(",", table.Columns.Select(t => t.ToString())), engine: table.Engine // , indexes: table.Indexes, temporary:temporary, ifNotExists: ifNotExists, db: db, cluster: table.Cluster); public string CreateTable(string columnsWithType, ITableEngine engine, string db = null, bool ifNotExists = false, string cluster = null) => CreateTable(table: TableName, db: db, columnsWithType: columnsWithType, engine: engine, temporary: IsTemporary, ifNotExists: ifNotExists, cluster: cluster);
public ViewCommandText(ClickHouseSchema schema, string viewName, IFromExpression fromExpr, ITableEngine engine = null, params (string Name, string Alias)[] columns)
public void Create(ClickHouseConnection conn, ITableEngine engine, string db, bool ifNotExists = false, string cluster = null) => conn.Execute(CommandText.CreateTable(GetColumnsWithTypes(), engine: engine, db: db, ifNotExists: ifNotExists, cluster: cluster));