All Projects → singerxt → ElasticModels

singerxt / ElasticModels

Licence: other
ElasticModels is a elasticsearch object modeling tool designed to work in and asynchronous environment. Builded for official elasticsearch client library Main inspiration was mongoose project

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ElasticModels

BMExport
一个 JSON 转 Objective-C,Swift class, Swift struct Model 属性的 Mac 小工具,【点击直接下载 https://github.com/liangdahong/BMExport/releases/download/2.0/BMExport2.0.dmg 】。
Stars: ✭ 22 (+69.23%)
Mutual labels:  model
modelsafe
A type-safe data modelling library for TypeScript
Stars: ✭ 13 (+0%)
Mutual labels:  model
ethereum-economic-model
A modular dynamical-systems model of Ethereum's validator economics
Stars: ✭ 79 (+507.69%)
Mutual labels:  model
sttp-model
Simple Scala HTTP model
Stars: ✭ 30 (+130.77%)
Mutual labels:  model
json-schema-js-gui-model
Handy gui model and associated translator that can be used to construct javascript UI forms from json-schemas
Stars: ✭ 19 (+46.15%)
Mutual labels:  model
modelforge
Python library to share machine learning models easily and reliably.
Stars: ✭ 18 (+38.46%)
Mutual labels:  model
compose plantuml
Generate Plantuml graphs from docker-compose files
Stars: ✭ 77 (+492.31%)
Mutual labels:  model
database-all
Eloquent ORM for Java 【database-spring-boot-starter】
Stars: ✭ 151 (+1061.54%)
Mutual labels:  model
yii2-rest-client
REST client (AR-like model) for Yii Framework 2.0 (via yii2-http-client)
Stars: ✭ 19 (+46.15%)
Mutual labels:  model
Faker.Portable
C# faked data generation for testing and prototyping purpose.
Stars: ✭ 12 (-7.69%)
Mutual labels:  model
tensorflow-stack-ts
TensorFlow.js Full-Stack Starter Kit
Stars: ✭ 33 (+153.85%)
Mutual labels:  model
pixel-art
A minimalist, cross device compatible pixel art editor.
Stars: ✭ 72 (+453.85%)
Mutual labels:  javascript-applications
blender-importer-unity
A tool to fix orientation issues from Blender to Unity
Stars: ✭ 23 (+76.92%)
Mutual labels:  model
FireSnapshot
A useful Firebase-Cloud-Firestore Wrapper with Codable.
Stars: ✭ 56 (+330.77%)
Mutual labels:  model
laravel-record
What if Laravel's Collection and Model classes had a baby?
Stars: ✭ 21 (+61.54%)
Mutual labels:  model
mutable
State containers with dirty checking and more
Stars: ✭ 32 (+146.15%)
Mutual labels:  model
javascript
in this project, I will add Javascript functions from Basics to Advanced with design patterns
Stars: ✭ 41 (+215.38%)
Mutual labels:  javascript-applications
mcnp
📊复杂网络建模课程设计. The project of modeling of complex networks course.
Stars: ✭ 69 (+430.77%)
Mutual labels:  model
hephaestus-engine
Render, animate and interact with custom entity models in Minecraft: Java Edition servers
Stars: ✭ 77 (+492.31%)
Mutual labels:  model
Apollo
A basic Application with multiple functionalities built with FastAPI aim to help Users Buy New Items Provided using PaypalAPI 🚀
Stars: ✭ 22 (+69.23%)
Mutual labels:  model

ElasticModels

dep ready? js-standard-style Build Status

ElasticModels is a elasticsearch object modeling tool designed to work in and asynchronous environment. Builded for official elasticsearch client library Main inspiration was mongoose project.

Documentation

WIP

Installation

WIP

Overview

Connecting to Elasticsearch

First, we need to define a connection.

const elasticsearch = require('elasticsearch');
const client = new elasticsearch.Client({
  host: 'localhost:9200',
  log: 'trace'
});
const { schema } = require('./lib')(client, {});

Defining a Model

Models are defined through the schema interface.

const elasticsearch = require('elasticsearch');
const client = new elasticsearch.Client({
  host: 'localhost:9200',
  log: 'trace'
});
const { schema, types } = require('./lib')(client, {})
const { string, integer, object, array } = types

const video = schema('video', {
  id: {
    type: string
  },
  length: {
    type: integer
  },
  description: {
    type: string
  },
  descriptionShort: {
    type: string,
    dependencies: ['description'],
    translation: description => description.subString(0, 20) + '...'
  },
  comments: { //Async field
    type: array,
    dependencies: ['videoId'],
    translation: videoId => getVideoCommentsForId('id') // this returning Promise
  }, {
    index: 'video', // required! elastic search index
    type: 'fullEpisode' // required! elasticsearch type
  },
});

Field definition

You have couple options to define field in schema. The most simple is

  1. Simple field. This field will looks if id exist in data and return value.
id: {
  type: string,
}
  1. Field with string translation. If you need to get value from object type field you can use define field like this.
name: {
  type: string,
  translation: 'namespace.description' // You can use dot notation. :-)
}
  1. Field with string translation with fallback. If you need to get value from field/object and if not exist you want to fallback from another data.
description: {
  type: string,
  translation: ['namespace.description, default.description'],
}
  1. Field with function as translation. If you need to execute code before feeling a field. (Sync)
description: {
  type: string,
  dependencies: ['namespace.description, default.description'],
  translate: (desc, defaultDesc, options) => {
    if (desc) {
      return desc;
    } else if(defaultDesc) {
      return defaultDesc;
    } else {
      return 'description not found :('
    }
  }
}
  1. Field with function as translation. If you need to populate field using another model or you need to pull data from different api you can return Promise from translation function.
articles: {
  type: array,
  dependencies: ['articlesIds'],
  translation: (articlesIds) => articleModel.find({id: articlesIds}).then(docs => docs.getDocuments)
}

Accessing a Model

Once we define model through schema('ModelName', mySchema), we can access it through the same function.

const video = schema('video', video);

video.find(query, options).then(documents => documents.getDocuments());

you can also findById

Important! .find method returning documents objects to access data you have to resolve documents.getDocuments()

Adding new methods for schema.

You can extend model using .addMethod(name, func) method.

const video = schema('video', video);

video.addMethod('findOnlyShortVideos', function () {
  return this.find({
    length: '..30000', // find videos what have length less then 30000ms.
  })
});

video.methods.findOnlyShortVideos().then(result => {
  console.log(result); // collection of videos what have length less then 30000ms.
});

Pagination

Model have build in pagination.

const video = schema('video', video);

video.find({}, {
  size: 30, // default 25
  from: 0, // default 0
}).then(result => {
  console.log(result); // first 30 objects
});

You can also delete extra method using .deleteMethod('findOnlyShortVideos')

Embedded Documents

WIP

Middleware

WIP

API Docs

License

The MIT License (MIT) Copyright (c) 2016 Mateusz Śpiewak.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].