百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

objection-find

> 编程语言
开源

使用 HTTP 查询参数为 objection.js 模型构建搜索查询。

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

使用 HTTP 查询参数为 objection.js 模型构建搜索查询。

Topics

  • Introduction
  • Installation
  • Getting started
  • Query parameters
  • Special parameters
  • Additional parameters
  • API documentation

Introduction

Note: since Objection.js (which this library is based on) now requires Node 6.0.0 as the minimum, objection-find will not work on node 5 console.log(persons[0].children); console.log(persons[0].movie); console.log(persons[0].parent.movies);

// Total size of the result if the range wasn't given. console.log(res.data.total); });

bash

In our example `Person` model had a one-to-one relation `parent`, a many-to-many relation `movies` and one-to-many
relation `children`. This example used the `$http` module of [AngularJS](https://angularjs.org/) but you can use
objection-find with anything that can send an HTTP request.

Documentation on the supported query parameters can be found [here](#query-parameters) and API documentation
[here](API.md).

It is recommended to use [query builder](https://www.npmjs.com/package/objection-find-query-builder) for constructing query parameters on the client side.

# Installation

```sh
npm install objection objection-find

Getting started

Easiest way to get started is to use the objection.js example project and copy paste this to the api.js file:

javascript
const findQuery = require('objection-find');

app.get('/persons/search', function (req, res, next) {
  findQuery(Person).build(req.query).then(function (persons) {
    res.send(persons);
  }).catch(next);
});

You also need to run this in the root of the example project to install objection-find:

bash
npm install --save objection-find

Now you can start bombing the /persons/search route. Documentation on the supported query parameters can be found here.

Query parameters

Objection-find understands two kinds of query parameters: filters and special parameters.

Filters

A filter parameter has the following format:

||...:=

…


firstName:eq=Jennifer&parent.age:lt=60&children.firstName:like=%rad%

…

js
const findQuery = require('objection-find');

app.get('/persons', function (req, res, next) {
  const { page, ...query } = req.query;
  
  findQuery(Person)
    .build(query, Person.query().page(page, 12))
    .then(function (persons) {
      res.send(persons);
    })
    .catch(next);
});

Issues· 28 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言