Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
typeorm-express-query-builder
Advanced tools
Readme
Easily transform an Express req.query into TypeORM query
Contributing
·
License
This library allows you to transfrom automatically Express.js req.query into TypeORM findOptions queries.
npm install typeorm-express-query-builder
Use QueryBuilder export from package and pass your req.query
as an argument:
import QueryBuilder from 'typeorm-express-query-builder'
const builder = new QueryBuilder(req.query)
const builtQuery = builder.build()
// Now your query is built, pass it to your TypeORM repository
const results = await fooRepository.find(builtQuery)
Given the following url query string:
foo/?name__contains=foo&role__in=admin,common&age__gte=18&page=3&limit=10
It will be transformed into:
{
where: {
foo: Like('%foo%'),
role: In(['admin', 'common']),
age: MoreThanOrEqual(18)
},
skip: 20,
take: 10
}
GET foo/?name__contains=foo&role__in=admin,common&age__gte=18&page=3&limit=10
POST foo/?name__contains=foo&role__in=admin,common&age__gte=18&page=3&limit=10
app.get('/foo', (req, res) => {
const queryBuilder = new QueryBuilder(req.query) // => Parsed into req.query
const built = queryBuilder.build()
})
POST foo/, body: {
"name__contains": "foo",
"role__in": "admin,common",
"age__gte": 18,
"page": 3,
"limit": 10
}
app.post('/foo', (req, res) => {
const queryBuilder = new QueryBuilder(req.body) // => Parsed into req.body
const built = queryBuilder.build()
})
Lookup | Behaviour | Example |
---|---|---|
(none) | Return entries that match with value | foo=raul |
contains | Return entries that contains value | foo__contains=lopez |
startswith | Return entries that starts with value | foo__startswith=r |
endswith | Return entries that ends with value | foo__endswith=dev |
icontains | Return entries that contains value and ignoring case | foo__icontains=Lopez |
istartswith | Return entries that starts with value and ignoring case | foo__istartswith=R |
iendswith | Return entries that ends with value and ignoring case | foo__iendswith=Dev |
isnull | Return entries with null value | foo__isnull |
lt | Return entries with value less than or equal to provided | foo__lt=18 |
lte | Return entries with value less than provided | foo__lte=18 |
gt | Returns entries with value greater than provided | foo__gt=18 |
gte | Return entries with value greater than or equal to provided | foo__gte=18 |
in | Return entries that match with values in list | foo__in=admin,common |
between | Return entries in range (numeric, dates) | foo__between=1,27 |
Notice: you can use negative logic prefixing lookup with __not
.
Example:
foo__not__contains=value
Option | Default | Behaviour | Example |
---|---|---|---|
pagination | true | If true, paginate results. If false, disable pagination | pagination=false |
page | 1 | Return entries for page page | page=2 |
limit | 25 | Return entries for page page paginated by size limit | limit=15 |
Option | Default | Behaviour | Example |
---|---|---|---|
order | - | Order for fields:+ : Ascendant - : Descendant | order=+foo,-name,+surname |
Option | Default | Behaviour | Example |
---|---|---|---|
select | - | Fields to select as response. If no provided, it select all fields. | select=name,surname,foo.nested |
with | - | Entity relations to attach to query | with=posts,comments |
If you need to disable some capabilities, you can do using shortcuts to enable|disable
by default or provide a custom Profile.
A Profile describe capabilities that can be used by clients & its behaviour.
const qb = new QueryBuilder(req.query, 'enabled' | 'disabled' | ConfigProgile)
ConfigProfile
object looks like:
const customProfile: ConfigProfile = {
options: {
pagination: {
status: 'enabled',
paginate: true,
itemsPerPage: 25,
},
ordering: {
status: 'enabled',
},
relations: {
status: 'enabled',
},
select: {
status: 'enabled',
},
},
policy: 'skip',
}
Field | Default | Behaviour | Type |
---|---|---|---|
options | 'enabled' | Profile options | ProfileOptions |
policy | 'skip' | Policy to apply in cases client try use disabled options | FindPolicyType |
FAQs
Easily transform an Express req.query into TypeORM query
The npm package typeorm-express-query-builder receives a total of 612 weekly downloads. As such, typeorm-express-query-builder popularity was classified as not popular.
We found that typeorm-express-query-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.