npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elasticbone

v0.0.3

Published

Connect Backbone to Elasticsearch

Downloads

5

Readme

#Elasticbone

NOTE: This project is still in development, and not production ready. Though hopefully soon it will be.

Elasticsearch is an awesome document store, with a nice rest api. Backbone is an awesome MVC framework, where the model are defined to interact with a rest api. Elasticbone is an extension making it easy for Backbone models to be connected to Elasticsearch documents.

Elasticbone is usable in both a browser, or node.js server.

To install

npm install elasticbone

##Examples The easiest way to describe elasticbone is to give a few examples based on creating a blog.

Elasticbone = require 'elasticbone'

class User extends Elasticbone.ElasticModel

class Post extends Elasticbone.ElasticModel

class Posts extends Elasticbone.ElasticCollection
  model: Post

Elasticmodels and elasticcollections reference an elasticsearch server, index and type.

class User extends Neckbone.ElasticModel
  server: 'localhost:9000' 
  index: 'blog'
  type: 'user'

class Post extends Neckbone.ElasticModel
  server: 'localhost:9000' 
  index: 'blog'
  type: 'post'

class Posts extends Neckbone.ElasticCollection
  server: 'localhost:9000' 
  index: 'blog'
  type: 'post'

###Relationships Elasticbone also lets you define relationships between backbone models and elasticsearch documents.

To relate models together the has function is used, and options are passed to it. The basic structure is has 'attribute', Model, {options}

By default the relationship will be treated as a subdocument, e.g.

Given a Post document in elasticsearch looks like:

{
tags: [{name: 'foo'}, {name: 'bar'}]
}

This relationships would be defined using elasticbone as such,

class Tag extends Backbone.Model

class Tags extends Backbone.Collection

class Post extends Neckbone.ElasticModel
  ...
  @has 'tags', Tags

NOTE: Tag is not an ElasticModel as it is not a document in Elasticsearch.

###has seperate ElasticModel relationship

class Posts extends Neckbone.ElasticCollection
  fetch_query: -> {"query":{"field": {"author":"\"#{this.get('user').name}\""}}}
    
class User extends Neckbone.ElasticModel
  ...
  @has 'posts', Posts, method: 'fetch'

user = new User(id: 1)
user.fetch(success: ->
  posts = user.get('posts')
)

When user.get('posts') the posts are fetched out of elasticsearch using the fetch_query which selects all posts where the field author is exactly the users name.

###Note: Circular has A problem occurs when a model wants to have reverse relations, e.g. a user has posts, and a post has a user.

As javascript will execute in order THIS CODE WILL NOT WORK, because when User references posts it will not exist yet.

class User extends Neckbone.ElasticModel
  @has 'posts', Posts

class Posts extends Neckbone.ElasticCollection
  @has 'author', User 

Instead you can use has after the classes declaration

class User extends Neckbone.ElasticModel

class Posts extends Neckbone.ElasticCollection
  @has 'author', User

User.has 'posts', Posts

##Development

Installation: npm inst Testing: npm test Contribution: Welcome

##Production release

Aimed support for

  1. has_one parse and fetch queries
  2. has_many parse and fetch queries
  3. Geographic Queries