async _setNullByValue({ tableName, columnName, value }) { return this._query() .table(tableName) .where(columnName, value) .update({ [columnName]: null }); }
async findOne(options): Promise<User> { const user = await this.userRepository.findOne({ select: options.select, where: options.where, }); return user; }
this.morphMany( GLOBALS[globalId], details.via, `${definition.collectionName}` ).query(qb => { qb.where(filter, name).orderBy('order'); })
bookshelf({ model }) { return ({ id }) => { return model .query(function(qb) { qb.where('username', 'LIKE', `%${id}%`).orWhere('email', 'LIKE', `%${id}%`); }) .fetchAll() .then(results => results.toJSON()); }; }
/** * index action * @return {Promise} [] */ async indexAction() { const page = this.get('page') || 1; const size = this.get('size') || 10; const name = this.get('name') || ''; const model = this.model('brand'); const data = await model.field(['id', 'name', 'floor_price', 'app_list_pic_url', 'is_new', 'sort_order', 'is_show']).where({name: ['like', `%${name}%`]}).order(['id DESC']).page(page, size).countSelect(); return this.success(data); }
handleFind(req) { const body = Object.assign(req.body, _ClassesRouter.default.JSONFromQuery(req.query)); const options = _ClassesRouter.default.optionsFromBody(body); return _rest.default.find(req.config, req.auth, '_Installation', body.where, options, req.info.clientSDK, req.info.context).then(response => { return { response: response }; }); }
function search(params, populate) { const filters = convertRestQueryParams(_.omit(params, '_q')); return model .query(qb => qb.where(buildSearchQuery({ model, params }))) .query(buildQuery({ model, filters })) .fetchAll({ withRelated: populate }) .then(results => results.toJSON()); }
async findById(id: number): Promise<Collection> { return await this.collectionRepository.createQueryBuilder('c') .select(['c.id', 'c.name', 'c.coverURL', 'c.announcement', 'c.allowPost', 'c.postMustAudit', 'c.creatorID', 'user.id', 'user.username', 'user.avatarURL']) .leftJoin('c.admins', 'user') .where('c.id = :id', { id }) .getOne(); }
async infoAction() { const id = this.get('id'); const model = this.model('order'); const data = await model.where({id: id}).find(); return this.success(data); }
orderingConditions(dbPath, f = identity) { return { [`${this.path}_lt`]: value => b => b.where(dbPath, '<', f(value)), [`${this.path}_lte`]: value => b => b.where(dbPath, '<=', f(value)), [`${this.path}_gt`]: value => b => b.where(dbPath, '>', f(value)), [`${this.path}_gte`]: value => b => b.where(dbPath, '>=', f(value)), }; }
function count(params) { const filters = convertRestQueryParams(params); return buildQuery({ model, filters: { where: filters.where }, }).count(); }
/** * index action * @return {Promise} [] */ async indexAction() { const page = this.get('page') || 1; const size = this.get('size') || 10; const name = this.get('name') || ''; const model = this.model('topic'); const data = await model.where({title: ['like', `%${name}%`]}).order(['id DESC']).page(page, size).countSelect(); return this.success(data); }
async detail(id: number): Promise<User> { return await this.userRepository.createQueryBuilder('user') .select(['user.id', 'user.createdAt', 'user.username', 'user.articleCount', 'user.articleViewCount', 'user.likedCount', 'user.uLikeCount', 'user.commentCount', 'user.job', 'user.company', 'user.introduce', 'user.personalHomePage', 'user.role', 'user.followerCount', 'user.followCount', 'user.avatarURL', 'user.sex', 'c.id', 'c.name', 'c.coverURL', 'c.creatorID', ]) .leftJoin('user.collections', 'c') .where('user.id = :id', { id }) .getOne(); }
this.morphMany( GLOBALS[globalId], details.via, `${definition.collectionName}` ).query(qb => { qb.where(filter, name).orderBy('order'); })
function count(params) { const filters = convertRestQueryParams(params); return buildQuery({ model, filters: { where: filters.where }, }).count(); }