GithubHelp home page GithubHelp logo

ozzie00 / salat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from salat/salat

1.0 2.0 0.0 5.24 MB

Fast bi-directional Scala case class to MongoDB mapping library

Home Page: https://github.com/novus/salat

License: Other

salat's Introduction

Salat

This project is an attempt to implement a fast MongoDB <-> Scala case class mapping mechanism. It is in fact my third stab at this problem; this time, I'm focusing on speed more than flexibility, compatibility, and functionality.

More information is availabe on the wiki. Salat-related discussion and questions belong on the mailing list.

Goals

  1. Convert an instance of any Scala case class to a DBObject suitable for insertion into a MongoDB database.

  2. Given a DBObject (which may have come from MongoDB, or elsewhere), instantiate an instance of the corresponding case class.

  3. Achieve goals 1 and 2 without sacrificing performance. This more or less rules out use of reflection.

  4. Achieve goals 1, 2, and 3 while adhering as much as feasible to core tenets of functional programming.

Goats sacrificed to the gods of performance

Considering above goals (especially 3), I have decided to make particular sacrifices and not look back.

No support for anything but case classes

Scala case classes are essentially products, and as such provide certain features which can be used to improve object serialization. These features include:

  • A simple and accessible constructor. Can be retrieved either by reflecting on the class itself, or through generated companion object.

  • Provided productIterator: a non-reflective way to retrieve programmatically values of the case class' data members.

  • Data members can have default values; information missing in DBObject instance during re-inflation can be subbed in using default args defined at compile time.

Requires ScalaSig

I hereby thank EPFL for the wonderfully undocumented ScalaSig. Fortunately, its source code reads like a work of art and isn't hard to comprehend. Obviously, if the previous section hasn't ruled out Java support, this certainly does.

ScalaSig does not appear to digest very well classes written in pure Java. Not a big deal, because we only support case classes anyway.

NB: it turns out that ScalaSig is incapable of "parsing" classes defined in the REPL, since there really is no .class file to parse. None of this code will work with classes that have no corresponding .class file.

Flexibility can wait

There's currently no way to alter default behavior of Salat's critical internal components. For example, it's impossible to tell it to exclude particular data members from (de)serialization. Similarly, the code is also not set up to even know anything about fields that aren't part of the case class constructor.

What's up with the name?

"Salat" is a transliteration of the Russian word "салат", for "salad". I picked this name because salad is great for your health and will not slow you down through use of runtime reflection.

salat's People

Contributors

jeffsack avatar maxaf avatar rktoomey avatar

Stargazers

 avatar

Watchers

 avatar  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.