Coder Social home page Coder Social logo

schwarzit / crystal-map Goto Github PK

View Code? Open in Web Editor NEW
13.0 17.0 3.0 6.49 MB

framework to generate map based entities classes / classes for named map interaction / parsing of complex classes to map structures

License: MIT License

Java 9.23% Kotlin 90.77%
couchbase-lite entityframework java kotlin mapping wrapper-library

crystal-map's Introduction

[Build Status codecov

CrystalMap Logo

A Framework for all Mapheads out there

What is this Framework about?

  • generate pojos for easy map interactions (@MapWrapper)
  • entity framework for all databases which represents it's data in maps (@Entity)
  • serialise/deserialise objects of complex classes in maps (@Mapper)

Quick View

@Entity / @MapWrapper

@Entity(database = "mydb_db")
@Fields(
        Field(name = "type", type = String::class, defaultValue = "product", readonly = true),
        Field(name = "name", type = String::class),
        Field(name = "comments", type = UserComment::class, list = true),
        Field(name = "image", type = Blob::class),
        Field(name = "identifiers", type = String::class, list = true)
)
@Queries(
        Query(fields = ["type"])
)
open class Product
@MapWrapper
@Fields(
        Field(name = "comment", type = String::class),
        Field(name = "user", type = String::class, defaultValue = "anonymous"),
        Field("age", type = Integer::class, defaultValue = "0")
)
open class UserComment

Result

        ProductEntity
                .create()
                .builder()
                .setName("Beer")
                .setComments(listOf(UserCommentWrapper
                        .create()
                        .builder()
                        .setComment("very awesome")
                        .exit()))
                .setImage(Blob("image/jpeg", resources.openRawResource(R.raw.ic_kaufland_placeholder)))
                .exit()
                .save()

        val allEntitiesOfType = ProductEntity.findByType()
        val resultOfAComplexQuery = ProductEntity.someComplexQuery("foo")

@Mapper

@Mapper
class MyViewModel : ViewModel() {

    @Mapify
    var innerObjectList: List<MyMapifyableTest> = listOf(MyMapifyableTest(simple))

    @Mapify
    var innerObjectMap: Map<String, MyMapifyableTest> = mapOf("test" to MyMapifyableTest(simple))

    @Mapify
    var testSerializable: TestSerializable = TestSerializable(simple, 5)

    @Mapify(nullableIndexes = [0])
    var product: ProductEntity? = null

    @Mapify
    var booleanValue: Boolean = true

    @Mapify(nullableIndexes = [0])
    var bigDecimalValue: BigDecimal? = null
}

Result

  // This is generated by the Annotation Processor
  val mapper = MyViewModelMapper()
  val oldObj = ViewModelProvider(this).get(MyViewModel::class.java)

  // Save obj to Map
  val mapToPersist = mapper.toMap(oldObj)

  val newObj = ViewModelProvider(this).get(MyViewModel::class.java)
  // restore obj
  mapper.fromMap(newObj, mapToPersist)

Implementation

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.