Giter Club home page Giter Club logo

arql-ops's Introduction

ArQL ops

Very tiny (53 lines including whitespace) library to build ArQL for queries for Arweave https://www.github.com/ArweaveTeam/arweave-js

Packaged up with https://github.com/pikapkg/pack, for web, node, typescript and even deno!

For fun, it's published on the on the arweave blockchain itself :)

npm install https://kybjhezuyftg.arweave.net/ITTPLYoxidZzAJP50FQ03QJUSkkh9iKHcmMcLZOvqtQ

  • PROS: exact dependency pinning, immutable blockchain so package can't be removed or replaced with something malicious. (although npm lockfiles and exact versions will take of this too)
  • CONS: not exactly easy to remember install line :D manual upgrades

This works because npm can install a .tgz file from any url, so it was just a matter of running pika build, tar'ing the pkg/ folder it produces, and uploading to arweave.

Also available on npm: npm install arql-ops

Usage examples

import { and, or, equals } from 'arql-ops';

const myQuery = and(
  equals('from', 'awalletaddressXyz'),
  equals('App-Name', 'super-app'),
  or(
    equals('someTag', '4'),
    equals('someTag', '5'),
    equals('someTag', '6')
  )
);

const results = await arweave.arql(myQuery);

With spread operators:

const myQuery = and(
  equals('App-Name', 'my-app'), 
  equals('myFooTag', 'bar'),
  or(
    ...listOfPossibleSomeTagValues.map(val => equals('someTag', val))
  )
);

const results = await arweave.arql(myQuery);

and() and or() will take any number of arguments and produce the correct Json of nested expressions:

const query = and(
  equals('my-super-tag', '1'),
  or(                                     
    equals('my-color-tag', 'red'), 
    equals('my-color-tag', 'blue'),
    equals('my-color-tag', 'purple'),
    equals('my-color-tag', 'orange'),
    equals('my-color-tag', 'white'),
    equals('my-color-tag', 'black'),
  )
);

This will produce a query that matches TXs with the tag 'my-super-tag'=1 , AND any of the color values that match 'my-color-tag'

Output Json:

{
  "op": "and",
  "expr1": {
    "op": "equals",
    "expr1": "my-super-tag",
    "expr2": "1"
  },
  "expr2": {
    "op": "or",
    "expr1": {
      "op": "equals",
      "expr1": "my-color-tag",
      "expr2": "red"
    },
    "expr2": {
      "op": "or",
      "expr1": {
        "op": "equals",
        "expr1": "my-color-tag",
        "expr2": "blue"
      },
      "expr2": {
        "op": "or",
        "expr1": {
          "op": "equals",
          "expr1": "my-color-tag",
          "expr2": "purple"
        },
        "expr2": {
          "op": "or",
          "expr1": {
            "op": "equals",
            "expr1": "my-color-tag",
            "expr2": "orange"
          },
          "expr2": {
            "op": "or",
            "expr1": {
              "op": "equals",
              "expr1": "my-color-tag",
              "expr2": "white"
            },
            "expr2": {
              "op": "equals",
              "expr1": "my-color-tag",
              "expr2": "black"
            }
          }
        }
      }
    }
  }
}

arql-ops's People

Contributors

therealaok avatar

Watchers

 avatar  avatar

Forkers

tmdwlsdktkfkdgo

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.