Beispiel #1
0
 public ulong RowCount(ClickHouseTable table)
 {
     using (ClickHouseConnection conn = new ClickHouseConnection(ConnectionSettings))
     {
         conn.Open();
         return(conn.GetRowCount(table.Name));
     }
 }
 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);
 }
Beispiel #3
0
 public T Max <T>(ClickHouseTable table, string columnName, string where = null)
 {
     using (ClickHouseConnection conn = new ClickHouseConnection(ConnectionSettings))
     {
         conn.Open();
         return(conn.GetMaxValue <T>(table.Name, columnName, where : where));
     }
 }
Beispiel #4
0
 public int Update(ClickHouseTable table, string where, params ColumnValue[] values)
 {
     using (ClickHouseConnection conn = new ClickHouseConnection(ConnectionSettings))
     {
         conn.Open();
         return(conn.Update(table.Name, where : where, values: values));
     }
 }
Beispiel #5
0
        public void TruncateTable(ClickHouseTable table, bool ifExists = false)
        {
            string cluster = CreateParameters.NodeMode == ClickHouseNodeMode.Replicated ? CreateParameters.Cluster : null;

            using (ClickHouseConnection conn = new ClickHouseConnection(ConnectionSettings))
            {
                conn.Open();
                table.Truncate(conn, db: ConnectionSettings.Database, ifExists: ifExists, cluster: cluster);
            }
        }
Beispiel #6
0
        public static void Insert <T>(this ClickHouseConnection conn, ClickHouseTable table, params T[] entities)
        {
            BatchData <T> data    = new BatchData <T>(entities);
            string        cmdText = $"INSERT INTO {(table.CommandText.IsTemporary ? "" : conn.ConnectionSettings.Database + ".")}{table.Name} ({BatchData<T>.GetFieldNames()}) VALUES @bulk";

            ProxyLog.Info(cmdText);
            using (var command = conn.CreateCommand(cmdText))
            {
                command.Parameters.Add(new ClickHouseParameter
                {
                    ParameterName = "bulk",
                    Value         = data
                });
                int rowsAffected = command.ExecuteNonQuery();
                if (rowsAffected == 0)
                {
                    rowsAffected = data.Count();
                }
                ProxyLog.Info($"{rowsAffected} row(s)");
            }
        }
Beispiel #7
0
 public void SetTable <T>(ClickHouseTable table) => _tables[typeof(T)] = table;