GithubHelp home page GithubHelp logo

qman's Introduction

Ultra lightweight query manager

  • super small bundle size 📦
  • manages deterministic query keys and invocations 🛠️
  • enhances type safety of existing fetching packages 🧪
  • organizes fetching structure into schemas 🫐
  • fully tree shake-able 🌴

Usage

import { query, schema } from 'qman'
import { use } from 'qman/swr' // or qman/query

// Specifies your getters, can be api route, db handlers, anything that returns a promise
const getAllUsers = () => fetch('your.api/users/')
const getUserById = (id: string) => fetch(`your.api/users/${id}`)

// Specifies a schema that organizes your api, declare multiple schemas based on category
export const users = schema(
  'users',
  query('allUsers', getAllUsers, use), 
  query('byId', getUserById, use),
  query('somePromise', directDBPromiseFn) // note we don't have to use swr/query adapters here
)

// Later in code (usually in different file) use your schema.
users.get('allUsers', [])
users.get('byId', ['exampleId123']) // You get full type-safety here with exact argument names i.e. `[id: string]`

This also ensures your query keys are always unique even if different schemas have same queries. i.e. you can have a schema called users and posts which both ship byId query. You can be sure and safe that even if you mutate / revalidate, it will stay within the schema boundaries and will get type safety according to schema definitions.

Advanced usage

Adds support for advanced query usage, such as

  • firebase
  • subscriptions
  • infinite and paginated queries
  • mutations
  • and more

documentation will come with beta release, will expand on these topics.

qman's People

Contributors

samuelhulla avatar

Stargazers

Jakub Schenk avatar Hector Sosa avatar  avatar Drahoslav Bednář avatar

Watchers

 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.