コード例 #1
0
        public async Task <T[]> GetMultiple(T model)
        {
            var command = new NpgsqlCommand();

            var retrieved = new List <T>();

            command.CommandText = $"SELECT {ORMQueryHelper.GetSelectColumns<T>()} FROM {tableName} WHERE {String.Join("AND", WhereCriteria(model, command, DataColumnUsage.Retrieve, null))}";
            await db.CommandReaderAsync(command, (reader) =>
            {
                T row = default(T);
                LoadModel(reader, row);
                retrieved.Add(row);
            });

            return(retrieved.ToArray());
        }
コード例 #2
0
        public async Task <DropshipItemModel> GetOneByID(int id)
        {
            var command = new NpgsqlCommand();

            command.CommandText = $"SELECT {ORMQueryHelper.GetSelectColumns<DropshipItemModel>()} FROM {tableName} WHERE id=@id";
            command.Parameters.AddWithValue("@id", id);

            var item = new DropshipItemModel();

            await db.CommandReaderAsync(command, reader =>
            {
                item = new DropshipItemModel();
                LoadModel(reader, item);
            });

            return(item);
        }
コード例 #3
0
        public async Task <T> GetOne(T model)
        {
            var command = new NpgsqlCommand();

            T retrieved = default(T);

            command.CommandText = $"SELECT {ORMQueryHelper.GetSelectColumns<T>()} FROM {tableName} WHERE {String.Join("AND", WhereCriteria(model, command, DataColumnUsage.Retrieve, null))}";
            await db.CommandReaderAsync(command, (reader) =>
            {
                while (reader.Read())
                {
                    LoadModel(reader, retrieved);
                }
            });

            return(retrieved);
        }
コード例 #4
0
        public async Task <DropshipAccount> GetOneByUsername(string username)
        {
            var command = new NpgsqlCommand();

            command.CommandText = $"SELECT {ORMQueryHelper.GetSelectColumns<DropshipAccount>()} FROM {tableName} WHERE username=@username";
            command.Parameters.AddWithValue("@username", username);

            DropshipAccount account = null;

            await db.CommandReaderAsync(command, reader =>
            {
                account = new DropshipAccount();
                LoadModel(reader, account);
            });

            return(account);
        }
コード例 #5
0
        public async Task <DropshipItemModel[]> GetMultipleByUsername(string username)
        {
            var command = new NpgsqlCommand();

            command.CommandText = $"SELECT {ORMQueryHelper.GetSelectColumns<DropshipItemModel>()} FROM {tableName} WHERE username=@username";
            command.Parameters.AddWithValue("@username", username);

            var items = new List <DropshipItemModel>();

            await db.CommandReaderAsync(command, reader =>
            {
                var item = new DropshipItemModel();
                LoadModel(reader, item);
                items.Add(item);
            });

            return(items.ToArray());
        }
コード例 #6
0
        public async Task <DropshipAccountItem[]> GetMultipleWithAccount(int take, int skip)
        {
            var accountTableName = ORMQueryHelper.GetTableName <DropshipAccount>();

            var command = new NpgsqlCommand();

            command.CommandText = $"SELECT {ORMQueryHelper.GetSelectColumns<DropshipItemModel>()},{ORMQueryHelper.GetSelectColumns<DropshipAccount>()} FROM {tableName} JOIN {accountTableName} ON {tableName}.username={accountTableName}.username LIMIT {take} OFFSET {skip};";

            var items = new List <DropshipAccountItem>();

            await db.CommandReaderAsync(command, reader =>
            {
                var item = new DropshipAccountItem();
                reader.ReadModel <DropshipItemModel>(item.Item);
                reader.ReadModel <DropshipAccount>(item.Account);
                items.Add(item);
            });

            return(items.ToArray());
        }
コード例 #7
0
        public async Task <DropshipAccountItem[]> GetMultipleWithAccountByUsername(string username)
        {
            var accountTableName = ORMQueryHelper.GetTableName <DropshipAccount>();

            var command = new NpgsqlCommand();

            command.CommandText = $"SELECT {ORMQueryHelper.GetSelectColumns<DropshipItemModel>()},{ORMQueryHelper.GetSelectColumns<DropshipAccount>()} FROM {tableName} JOIN {accountTableName} ON {tableName}.username={accountTableName}.username WHERE {tableName}.username=@username;";
            command.Parameters.AddWithValue("@username", username);

            var items = new List <DropshipAccountItem>();

            await db.CommandReaderAsync(command, reader =>
            {
                var item = new DropshipAccountItem();
                reader.ReadModel <DropshipItemModel>(item.Item);
                reader.ReadModel <DropshipAccount>(item.Account);
                items.Add(item);
            });

            return(items.ToArray());
        }