Example #1
0
        public virtual string CreateTableQuery(CreateTableQuery query)
        {
            StringBuilder str = new StringBuilder();

            str.AppendFormat("CREATE TABLE `{0}` (\n", query.tableName);

            foreach (TableField field in query.fields)
            {
                str.AppendFormat("\t{0},\n", TableField(field, false));
            }

            StringBuilder keys = new StringBuilder();
            foreach (TableField key in query.fields.Where(f => f.Key.HasFlag(KeyType.Primary)))
            {
                if (keys.Length > 0)
                    keys.Append(", ");
                keys.AppendFormat("`{0}`", key.Name);
            }

            if (keys.Length > 0)
                str.AppendFormat("\tPRIMARY KEY ({0})", keys.ToString());

            str.Append("\n);");
            return str.ToString();
        }
Example #2
0
        /// <summary>
        /// Create an executa a CREATE TABLE query, using the
        /// DbField attributes on the given type T.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public Task CreateTable <T>()
        {
            CreateTableQuery <T> query = new CreateTableQuery <T>(Builder);

            return(ExecuteNonQuery(query));
        }