Giter Site home page Giter Site logo

nomilkinmyhome / elasticmapper Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 0.0 72 KB

Easy generating ElasticSearch mappings based on ORM's models.

Home Page: https://elasticmapper.readthedocs.io/en/latest/index.html

License: MIT License

Python 100.00%
codegen elasticsearch mapping django peewee sqlalchemy

elasticmapper's Introduction

ElasticMapper

ElasticSearch mapper for three ORMs - SQLAlchemy, Peewee, DjangoORM.
Easy generating ElasticSearch mappings based on models.

Installation

pip install elasticmapper

Basic usage

Peewee example

from peewee import *
from elasticmapper import PeeweeMapper

db = SqliteDatabase('my_app.db')

class BaseModel(Model):
    class Meta:
        database = db

class User(BaseModel):
    username = CharField(unique=True)
    is_active = BooleanField(default=True)
    age = IntegerField()

user_elastic_mapping = PeeweeMapper(model=User).load()

SQLAlchemy example

from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String, Boolean
from elasticmapper import SQLAlchemyMapper

Base = declarative_base()

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    username = Column(String)
    is_active = Column(Boolean)
    age = Column(Integer)

user_elastic_mapping = SQLAlchemyMapper(model=User).load()

DjangoORM example

from django.db import models
from elasticmapper import DjangoMapper

class User(models.Model):
    username = models.CharField(max_length=30)
    is_active = models.BooleanField(default=True)
    age = models.IntegerField()

user_elastic_mapping = DjangoMapper(model=User).load()

Output for all examples:

{
    'id': {'type': 'integer'},
    'username': {'type': 'text'},
    'age': {'type': 'integer'},
    'is_active': {'type': 'boolean'}
}

Documentation

Documentation lives here.

Contributing

PR are welcome! If you want to help, please visit the contribution guide, then take one of the issues. Thank you for your contribution.

License

Copyright © 2022 Polina Beskorovaynaya ihatemilk

This project has MIT License.

elasticmapper's People

Contributors

nomilkinmyhome avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

elasticmapper's Issues

improve tests

add pytest.mark.parametrize for each test with different cases

add custom values

new parameter for load() - custom_values.
it will be a dict that contains custom values per field.
for example:

from django.db import models

from elasticmapper import load, SupportedORMs

class User(models.Model):
    username = models.CharField(max_length=30)
    timestamp = models.DateTimeField()

custom_values = {'timestamp': {'type': 'date', 'format': `'yyyy-MM-dd'}}
user_elastic_mapping = load(
    model=User, 
    orm=SupportedORMs.DjangoORM,
    custom_values=custom_values,
)

expected output:

{
    'id': 'int',
    'username': 'text',
    'timestamp': {
        'type': 'date',
        'format': 'yyyy-MM-dd'
    }
}

add tests and linters

install pytest and flake8.
tests should cover common use cases: one test for each load() parameter and tests for each supported orm.

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.