示例#1
0
        /// <summary>
        /// Inserts a new record into the table.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="tableName">Name of the table to insert into.</param>
        /// <param name="values">The values that will be added to the table. Can be anything that can be converted to a property bag.</param>
        /// <returns>The newly inserted row.</returns>
        public async static Task <dynamic> InsertAsync(this BaDatabase db, string tableName, object values)
        {
            var conn = await db.GetConnectionAsync().ConfigureAwait(false);

            var cmd = conn.CreateCommand();

            PrepareInsertCmd(cmd, tableName, values);
            return(await db.GetDynamicAsync(cmd).ConfigureAwait(false));
        }
示例#2
0
        /// <summary>
        /// Deletes the records with the given key.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="tableName">Name of the table to remove records from.</param>
        /// <param name="key">Key of the record to delete. Can be anything that can be converted to a property bag.</param>
        /// <returns></returns>
        public async static Task <int> DeleteAsync(this BaDatabase db, string tableName, object key)
        {
            var conn = await db.GetConnectionAsync();

            var cmd = conn.CreateCommand();

            PrepareDeleteCmd(cmd, tableName, key);
            return(await db.ExecuteNonQueryAsync(cmd).ConfigureAwait(false));
        }
示例#3
0
        internal static async Task <DbCommand> PrepareSprocCmdAsync(this BaDatabase db, string sprocName, object parameters)
        {
            var conn = await db.GetConnectionAsync().ConfigureAwait(false);

            var cmd = conn.CreateCommand();

            cmd.CommandText = sprocName;
            cmd.CommandType = CommandType.StoredProcedure;

            if (parameters != null)
            {
                cmd.AddParameters(parameters);
            }

            return(cmd);
        }