Code Monkey home page Code Monkey logo

array-ql's Introduction

Array-Query

npm version npm downloads bundle JSDocs License

Query JavaScript arrays with ORM-like syntax, benefiting from excellent type-safety & developer experience.

Key Features:

  • ๐Ÿ›  Type-safe Querying: Design your queries with strong typing (typed sort / search / filter keys & output)
  • ๐Ÿ“„ Pagination: Easily paginate through large datasets with built-in support.
  • ๐Ÿ”Ž Full-text Search: Perform comprehensive searches across multiple fields in your data.
  • ๐Ÿงญ Advanced Filtering: Apply complex filters with various match modes for precise data retrieval. Supports logical grouping, nested conditions, and array matching.
  • ๐Ÿ”ข Flexible Sorting: Order results based on any field, with support for multiple sort criteria.
  • ๐Ÿš€ Lightweight and Fast: Queries stay super fast, even with large datasets.
  • ๐Ÿงฉ Zero Dependencies: Completely self-contained with no external dependencies, ensuring a small bundle cost

INSTALLATION

// npm
npm install @chronicstone/array-query

// yarn
yarn add @chronicstone/array-query

// pnpm
pnpm add @chronicstone/array-query

// bun
bun add @chronicstone/array-query

USAGE EXAMPLE

import { query } from '@chronicstone/array-query'

const users = [
  { id: 1, fullName: 'John Doe', email: '[email protected]', age: 30, status: 'active', roles: ['admin'], createdAt: '2023-01-01' },
  { id: 2, fullName: 'Jane Smith', email: '[email protected]', age: 28, status: 'inactive', roles: ['user'], createdAt: '2023-02-15' },
  { id: 3, fullName: 'Bob Johnson', email: '[email protected]', age: 35, status: 'active', roles: ['user', 'manager'], createdAt: '2023-03-20' },
  // ... more users
]

const { totalRows, totalPages, rows } = query(users, {
  // Pagination
  page: 1,
  limit: 10,

  // Sorting
  sort: [
    { key: 'age', dir: 'desc' },
    { key: 'fullName', dir: 'asc' }
  ],

  // Searching
  search: {
    value: 'john',
    keys: ['fullName', 'email']
  },

  // Filtering
  filter: [
    { key: 'status', matchMode: 'equals', value: 'active' },
    { key: 'age', matchMode: 'greaterThan', value: 25 },
  ]
})

This example demonstrates pagination, multi-field sorting, full-text searching, and complex filtering with nested conditions and array field matching.

License

MIT License ยฉ 2023-PRESENT Cyprien THAO

array-ql's People

Contributors

chronicstone avatar vampirechicken12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.