Git Product home page Git Product logo

esfq's Introduction

ESFQ

๐Ÿ” Functional queries for ECMAScript

Functions

deleteFrom

Removes an item from the dataset where condition matches.

const { result } = deleteFrom<Item>(data).where((item) => item.id === 2);

Note: Unlike SQL, there is no default behavior for deleteFrom. If you want to remove all items from the dataset, pass Boolean or () => true to where().

Methods

  • where

insertInto

Adds an item to the dataset.

const { result } = insertInto<Item>(data).set({ id: 3, name: "cashews" });

Methods

  • set

selectFrom

Returns items that match the provided conditions

const { result } = selectFrom<Item>(data)
  .where(({ value }) => value > 4)
  .orderBy("id", "ASC")
  .columns(["name", "value"]);

Notes: Unlike SQL, the order of the statements matters.

Methods

  • columns
  • orderBy
  • where

update

Updates all of the items which match the provided condition

const { result } = update<Item>(data)
  .where((item) => item.id === 3)
  .set((item) => ({ ...item, name: "hazelnuts" }));

Methods

  • set
  • where

Schema

To reduce the boilerplate for creating functional queries, you can use the Schema function:

const fq = Schema<Item>();

fq.deleteFrom(data).where(/* ... */);
fq.insertInto(data).values(/* ... */);
fq.selectFrom(data).columns(/* ... */);
fq.update(data).where(/* ... */);

The functions returned all received the initial item type.

If you are working with an external data source like localStorage, you can go one step further and pass a resolver to Schema:

const fq = Schema<Item>(() =>
  JSON.stringify(localStorage.getItem("example") as Item[])
);

fq.deleteFrom().where(/* ... */);
fq.insertInto().values(/* ... */);
fq.selectFrom().columns(/* ... */);
fq.update().where(/* ... */);

License

ISC ยฉ 2021 Sean McPherson

esfq's People

Contributors

seanmcp avatar

Watchers

James Cloos 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.