npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adonis-search

v1.0.3

Published

Mail provider for adonis framework and has support for all common mailing services to send emails

Downloads

230

Readme

Adonis Search

This is repo is a AdonisJs provider for simplicity work with search in adonis-lucid

npm version Build Status Coverage Status

Install

npm i --save adonis-search

Registering provider

The provider is registered inside start/app.js file under providers array.

const providers = [
  'adonis-query/providers/QueryProvider'
]

That's all! Now you can use the mail provider as follows.

Sample

Request url is GET /users?search=mark&page=2&order=-email

const Route = use('Route')
const Query = use('Query')
const User = use('App/Models/User')

Route.get('/users', async ({ request, response }) => {
  const query = new Query(request, { order: 'id' })
  const order = query.order()
  
  const users = await User.query()
    .where(query.search([
      'first_name',
      'last_name',
      'email'
    ]))
    .orderBy(order.column, order.direction)
    .paginate(query.page(), query.limit())
    
  response.json(users)
})

Usage

Default values

{
  "page": 1,
  "limit": 30,
  "search": ""
}

You can change defaults by send second argument in Query constructor

cosnt query = new Query(request, {
  limit: 50
})

Search

Note 1. Search not fire where clause if search variable is empty.

Note 2. All search columns and values will be translated to lowercase.

For basic usage you need add columns where you make search

const query = new Query(request, { order: 'id' })
const users = await User.query()
  .where(query.search([
    'first_name',
    'last_name',
    'email'
  ]))

If you need search in INT columns, you need set first argument as object with columns types:

const query = new Query(request, { order: 'id' })
const users = await User.query()
  .where(query.search({
    id: Query.INT,
    first_name: Query.STRING,
    last_name: Query.STRING,
    email: Query.STRING
  }))

Paginate

You can get parsed values from uri as page and limit. Variables are optional.

Route.get('/users', async ({ request, response }) => {
  const query = new Query(request)
  const users = await User.query()
    .paginate(query.page(), query.limit())
    
  response.json(users)
})

Order by

For use order by you need set default value order by column for query

const query = new Query(request, { order: 'id' })
const order = query.order()
const users = await User.query()
  .orderBy(order.column, order.direction)
  .fetch()

Reverse sort are supported by set first symbol - before name column. Sample uri as /users?order=-email It's native support for AngularJS applications.