Example #1
0
        public static void CreateTable(this CrateConnection conn, Type t)
        {
            var tabledata = AttributeHelpers.GetTableData(t);
            var tablecols = CrateFieldCacheProvider.Instance.Get(t);

            var sb = new StringBuilder();

            sb.Append("CREATE TABLE ").Append(tabledata.Name).Append(" ( ");
            sb.Append(LoopObject(t));

            var pk = tablecols.Where(tc => tc.Value.PrimaryKey).Select(tc => tc.Value.Name).ToArray();

            if (pk.Any())
            {
                sb.Append("primary key (").Append(string.Join(" ,", pk)).Append(" )");
            }
            else
            {
                sb.Remove(sb.Length - 2, 2);
            }
            sb.Append(" ) ");

            sb.Append(string.Format("clustered into {0} shards ", tabledata.NumberOfShards));
            sb.Append(string.Format(" with (number_of_replicas = '{0}') ", EnumHelpers.Replication(tabledata.NumberOfReplicas)));

            var sql = sb.ToString();

            using (var cmd = new CrateCommand(sql, conn))
            {
                cmd.ExecuteNonQuery();
            }
        }
Example #2
0
        public static void DropTable(this CrateConnection conn, string name)
        {
            var sql = "DROP TABLE" + name;

            using (var cmd = new CrateCommand(sql, conn))
            {
                cmd.ExecuteNonQuery();
            }
        }
        public static int Delete <T>(this CrateConnection conn, Expression <Func <T, bool> > exp)
        {
            var table = AttributeHelpers.GetTableData(typeof(T));

            var swhere = "DELETE FROM " + table.Name + " WHERE " + (new WhereTranslater()).Translate(exp);

            using (var cmd = new CrateCommand(swhere, conn))
            {
                return(cmd.ExecuteNonQuery());
            }
        }