Giter Club home page Giter Club logo

lyra's Introduction

Lyra

Tests

Try the live demo

Installation

You can install Lyra using npm, yarn, pnpm:

npm i @nearform/lyra
yarn add @nearform/lyra
pnpm add @nearform/lyra

Usage

Lyra is quite simple to use. The first thing to do is to create a new database instance and set an indexing schema:

import { create, insert, search, remove } from '@nearform/lyra';

const db = create({
  schema: {
    author: 'string',
    quote: 'string'
  }
});

Lyra will only index string properties, but will allow you to set and store additional data if needed.

Once the db instance is created, you can start adding some documents:

insert(db, {
  quote: 'It is during our darkest moments that we must focus to see the light.',
  author: 'Aristotle'
});

insert(db, {
  quote: 'If you really look closely, most overnight successes took a long time.',
  author: 'Steve Jobs'
});

insert(db, {
  quote: 'If you are not willing to risk the usual, you will have to settle for the ordinary.',
  author: 'Jim Rohn'
});

insert(db, {
  quote: 'You miss 100% of the shots you don\'t take',
  author: 'Wayne Gretzky - Michael Scott'
});

After the data has been inserted, you can finally start to query the database.

const searchResult = search(db, {
  term: 'if',
  properties: '*'
});

In the case above, you will be searching for all the documents containing the word if, looking up in every schema property (AKA index):

{
  elapsed: 99, // elapsed time is in microseconds
  hits: [
    {
      id: 'ckAOPGTA5qLXx0MgNr1Zy',
      quote: 'If you really look closely, most overnight successes took a long time.',
      author: 'Steve Jobs'
    },
    {
      id: 'fyl-_1veP78IO-wszP86Z',
      quote: 'If you are not willing to risk the usual, you will have to settle for the ordinary.',
      author: 'Jim Rohn'
    }
  ],
  count: 2
}

You can also restrict the lookup to a specific property:

const searchResult = search(db, {
  term: 'Michael',
  properties: ['author']
});

Result:

{
  elapsed: 111,
  hits: [
    {
      id: 'L1tpqQxc0c2djrSN2a6TJ',
      quote: "You miss 100% of the shots you don't take",
      author: 'Wayne Gretzky - Michael Scott'
    }
  ],
  count: 1
}

If needed, you can also delete a given document by using the remove method:

remove(db, 'L1tpqQxc0c2djrSN2a6TJ');

License

Lyra is licensed under the Apache 2.0 license.

lyra's People

Contributors

micheleriva avatar mateonunez avatar thomscoder avatar ishibi avatar danielefedeli avatar castarco avatar shogunpanda avatar rafaelgss avatar bozzelliandrea avatar matteogheza avatar ilteoood avatar paolo-cargnin avatar simonireilly avatar tianjos avatar frenzarectah 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.