コード例 #1
0
        public static int Update(this ClickHouseConnection conn, string tableName, string where, params ColumnValue[] values)
        {
            string commandText = $"ALTER TABLE {tableName} "
                                 + $"UPDATE {string.Join(",", values.Select(t => $"{t.Name}={t.Value.AsClickValue()}").ToArray())} WHERE {where}";

            return(conn.Execute(commandText));
        }
コード例 #2
0
        public void DropDatabase(bool ifExists = false)
        {
            string cluster = CreateParameters.NodeMode == ClickHouseNodeMode.Replicated ? CreateParameters.Cluster : null;

            using (ClickHouseConnection conn = new ClickHouseConnection(ConnectionSettings.GetConnectionWithoutDb()))
            {
                conn.Open();
                conn.Execute(DatabaseCommandText.DropDatabase(db: ConnectionSettings.Database, ifExists: ifExists, cluster: cluster));
            }
        }
コード例 #3
0
        protected virtual ClickHouseConnection CreateClickHouseConnection(string database = null)
        {
            string connectStr = $"Compress=True;CheckCompressedHash=False;Compressor=lz4;Host={_arguments.Host};Port={_arguments.Port};Database=system;User={_arguments.User};Password={_arguments.Password}";
            var    settings   = new ClickHouseConnectionSettings(connectStr);
            var    cnn        = new ClickHouseConnection(settings);

            cnn.Open();

            if (!string.IsNullOrWhiteSpace(database))
            {
                cnn.Execute($"USE {database};");
            }
            return(cnn);
        }
コード例 #4
0
        public void CreateDatabase(bool ifNotExists = false, CreateDatabaseMode mode = CreateDatabaseMode.All)
        {
            string cluster = CreateParameters.NodeMode == ClickHouseNodeMode.Replicated ? CreateParameters.Cluster : null;

            using (ClickHouseConnection conn = new ClickHouseConnection(ConnectionSettings.GetConnectionWithoutDb()))
            {
                conn.Open();
                conn.Execute(DatabaseCommandText.CreateDatabase(db: ConnectionSettings.Database, ifNotExists: ifNotExists, cluster: cluster));
                if ((mode & CreateDatabaseMode.Tables) != 0)
                {
                    Schema.Tables.ToList().ForEach(t => t.Create(conn, TableEngines[t.EntityType], db: ConnectionSettings.Database, ifNotExists: ifNotExists, cluster: cluster));
                }
                if ((mode & CreateDatabaseMode.Views) != 0)
                {
                    Schema.Views.ForEach(t => t.Create(conn, ConnectionSettings.Database, ifNotExists: ifNotExists));
                }
                if ((mode & CreateDatabaseMode.Dictionaries) != 0)
                {
                    Schema.Dictionaries.ForEach(t => t.Create(conn, db: ConnectionSettings.Database, ifNotExists: ifNotExists));
                }
            }
        }
コード例 #5
0
 public void Drop(ClickHouseConnection conn, string db, bool ifExists = false) =>
 conn.Execute(CommandText.DropView(db, ifExists: ifExists));
コード例 #6
0
 public void Create(ClickHouseConnection conn, string db, bool ifNotExists = false) =>
 conn.Execute(CommandText.CreateView(db, ifNotExists: ifNotExists));
コード例 #7
0
 static void CreateTable(ClickHouseConnection conn)
 {
     conn.Execute(
         "CREATE TABLE IF NOT EXISTS TestUser (ResisterDate Date, ResisterTime DateTime, Name String, Age UInt16) ENGINE=MergeTree(ResisterDate,(ResisterTime,Name,Age), 8192)");
     Console.WriteLine("Create table 'TestUser' success.");
 }
コード例 #8
0
 private void CreateTable(ClickHouseConnection conn)
 {
     conn.Execute(
         "CREATE TABLE IF NOT EXISTS TestUser (ResisterDate Date, ResisterTime  DateTime64(3) DEFAULT now64(3), Name String, Age UInt16) ENGINE=MergeTree(ResisterDate,(ResisterTime,Name,Age), 8192)");
 }
コード例 #9
0
        public static int Delete(this ClickHouseConnection conn, string tableName, string where)
        {
            string commandText = $"ALTER TABLE {tableName} DELETE WHERE {where}";

            return(conn.Execute(commandText));
        }
コード例 #10
0
        public static void Insert(this ClickHouseConnection conn, string tableName, params ColumnValue[] values)
        {
            string commandText = $"INSERT INTO {tableName}({string.Join(",", values.Select(t => t.Name).ToArray())}) VALUES ({string.Join(",", values.Select(t => t.Value.AsClickValue()).ToArray())})";

            conn.Execute(commandText);
        }
コード例 #11
0
 public void Truncate(ClickHouseConnection conn, string db, bool ifExists = false, string cluster = null) =>
 conn.Execute(CommandText.TruncateTable(db: db, ifExists: ifExists, cluster: cluster));
コード例 #12
0
 public void Drop(ClickHouseConnection conn, string db, bool ifExists = false, string cluster = null) =>
 conn.Execute(CommandText.DropTable(db: db, ifExists: ifExists));
コード例 #13
0
 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));