All Projects → florent37 → Freezer

florent37 / Freezer

Licence: apache-2.0
A simple & fluent Android ORM, how can it be easier ? RxJava2 compatible

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Freezer

Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+119.94%)
Mutual labels:  sql, orm, database, sqlite
Trilogy
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
Stars: ✭ 195 (-40.18%)
Mutual labels:  sql, database, sqlite, model
Ebean
Ebean ORM
Stars: ✭ 1,172 (+259.51%)
Mutual labels:  sql, orm, database, sqlite
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+1088.34%)
Mutual labels:  orm, entity, database, sqlite
Rxjava2 Operators Magician
你用不惯 RxJava,只因缺了这把钥匙 🔑 You are not used to RxJava, just because of the lack of this key.
Stars: ✭ 868 (+166.26%)
Mutual labels:  rxjava, rxjava2, rxandroid, rxjava-android
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (+65.34%)
Mutual labels:  sql, orm, database, sqlite
Nut
Advanced, Powerful and easy to use ORM for Qt
Stars: ✭ 181 (-44.48%)
Mutual labels:  sql, orm, database, sqlite
Android Orma
An ORM for Android with type-safety and painless smart migrations
Stars: ✭ 442 (+35.58%)
Mutual labels:  sql, orm, database, sqlite
Android Kotlin Mvp Architecture
This repository contains a detailed sample app that implements MVP architecture in Kotlin using Dagger2, Room, RxJava2, FastAndroidNetworking and PlaceholderView
Stars: ✭ 615 (+88.65%)
Mutual labels:  rxjava, rxjava2, rxjava-android, database
Rxbluetooth
Android reactive bluetooth
Stars: ✭ 405 (+24.23%)
Mutual labels:  rxjava, rxjava2, rxandroid, rx
Hunt Entity
An object-relational mapping (ORM) framework for D language (Similar to JPA / Doctrine), support PostgreSQL and MySQL.
Stars: ✭ 51 (-84.36%)
Mutual labels:  orm, entity, database, sqlite
Reactiveandroid
🚀 Simple and powerful ORM for Android
Stars: ✭ 102 (-68.71%)
Mutual labels:  rxjava, orm, database, sqlite
Linq2db
Linq to database provider.
Stars: ✭ 2,211 (+578.22%)
Mutual labels:  sql, orm, database, sqlite
Db
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Stars: ✭ 2,832 (+768.71%)
Mutual labels:  sql, orm, database, sqlite
Mvpframes
整合大量主流开源项目并且可高度配置化的 Android MVP 快速集成框架,支持 AndroidX
Stars: ✭ 100 (-69.33%)
Mutual labels:  rxjava, rxjava2, rxandroid, rxjava-android
Rxjavapriorityscheduler
RxPS - RxJavaPriorityScheduler - A RxJava Priority Scheduler library for Android and Java applications
Stars: ✭ 138 (-57.67%)
Mutual labels:  rxjava, rxjava2, rxandroid, rxjava-android
AndroidTutorials
Ejemplos Android [Dagger2,RxJava,MVP,Retrofit2,SQLite]
Stars: ✭ 22 (-93.25%)
Mutual labels:  sqlite, rxjava, rxandroid
RxAnimator
An RxJava2 binding for android Animator
Stars: ✭ 80 (-75.46%)
Mutual labels:  rxjava, rx, rxjava2
SQLitePractice
数据库案例:1.使用时间和日期函数,增,查时间字段。2.利用ContentProvider,CursorLoader,SQLite实现数据库的观察者模式。3.RxJava,SQLBrite实现数据库的观察者模式。4.拷贝外部db文件到数据库中
Stars: ✭ 21 (-93.56%)
Mutual labels:  sqlite, rxjava, rxandroid
Rxgps
Finding current location cannot be easier on Android !
Stars: ✭ 307 (-5.83%)
Mutual labels:  rxjava, rxjava2, rx

Freezer

Android Arsenal CircleCI

Android app on Google Play

A simple & fluent Android ORM, how can it be easier ? And it's compatible with RxJava2 !

UserEntityManager userEntityManager = new UserEntityManager();

userEntityManager.add(new User("Florent", 6));
userEntityManager.add(new User("Florian", 3));
userEntityManager.add(new User("Bastien", 3));

List<User> allUsers = userEntityManager.select()
                             .name().startsWith("Flo")
                             .asList();

userEntityManager.select()
       .age().equals(3)
       .asObservable()

       .subscribeOn(Schedulers.newThread())
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(users ->
          //display the users
       );

First, initialize !

Don't forget to initialise Freezer in your application:

public class MyApplication extends Application {

    @Override public void onCreate() {
        super.onCreate();
        Freezer.onCreate(this);
    }

}

Second, annotate your models

Use Annotations to mark classes to be persisted:

@Model
public class User {
    int age;
    String name;
    Cat cat;
    List<Cat> pets;
}
@Model
public class Cat {
    @Id long id;
    String name;
}

Now, play with the managers !

Persist datas

Persist your data easily:

UserEntityManager userEntityManager = new UserEntityManager();

User user = ... // Create a new object
userEntityManager.add(user);

Querying

Freezer query engine uses a fluent interface to construct multi-clause queries.

Simple

To find all users:

List<User> allUsers = userEntityManager.select()
                             .asList();

To find the first user who is 3 years old:

User user3 = userEntityManager.select()
                    .age().equalsTo(3)
                    .first();

Complex

To find all users

  • with name "Florent"
  • or who own a pet with named "Java"

you would write:

List<User> allUsers = userEntityManager.select()
                                .name().equalsTo("Florent")
                             .or()
                                .cat(CatEntityManager.where().name().equalsTo("Java"))
                             .or()
                                .pets(CatEntityManager.where().name().equalsTo("Sasha"))
                             .asList();

Selectors

//strings
     .name().equalsTo("florent")
     .name().notEqualsTo("kevin")
     .name().contains("flo")
     .name().in("flo","alex","logan")
//numbers
     .age().equalsTo(10)
     .age().notEqualsTo(30)
     .age().greatherThan(5)
     .age().between(10,20)
     .age().in(10,13,16)
//booleans
     .hacker().equalsTo(true)
     .hacker().isTrue()
     .hacker().isFalse()
//dates
     .myDate().equalsTo(OTHER_DATE)
     .myDate().notEqualsTo(OTHER_DATE)
     .myDate().before(OTHER_DATE)
     .myDate().after(OTHER_DATE)

Aggregation

The QueryBuilder offers various aggregation methods:

float agesSum      = userEntityManager.select().sum(UserColumns.age);
float agesAverage  = userEntityManager.select().average(UserColumns.age);
float ageMin       = userEntityManager.select().min(UserColumns.age);
float ageMax       = userEntityManager.select().max(UserColumns.age);
int count          = userEntityManager.select().count();

Limit

The QueryBuilder offers a limitation method, for example, getting 10 users, starting from the 5th:

List<User> someUsers = userEntityManager.select()
                                .limit(5, 10) //start, count
                                .asList();

Asynchronous

Freezer offers various asynchronous methods:

Add / Delete / Update

userEntityManager
                .addAsync(users)
                .async(new SimpleCallback<List<User>>() {
                    @Override
                    public void onSuccess(List<User> data) {

                    }
                });

Querying

userEntityManager
                .select()
                ...
                .async(new SimpleCallback<List<User>>() {
                    @Override
                    public void onSuccess(List<User> data) {

                    }
                });

Observables

With RxJava

userEntityManager
                .select()
                ...
                .asObservable()
                ... //rx operations
                .subscribe(new Action1<List<User>>() {
                    @Override
                    public void call(List<User> users) {
                    
                    }
                });

Entities

Freezer makes it possible, yes you can design your entities as your wish:

@Model
public class MyEntity {

    // primitives
    [ int / float / boolean / String / long / double ] field;
    
    //dates
    Date myDate;

    // arrays
    [ int[] / float[] / boolean[] / String[] / long[] / double ] array; 
    
    // collections
    [ List<Integer> / List<Float> / List<Boolean> / List<String> / List<Long> / List<Double> ] collection;
    
    // One To One
    MySecondEntity child;
    
    // One To Many
    List<MySecondEntity> childs;
}

Update

You can update a model:

user.setName("laurent");
userEntityManager.update(user);

Id

You can optionnaly set a field as an identifier:

@Model
public class MyEntity {
    @Id long id;
}

The identifier must be a long

Ignore

You can ignore a field:

@Model
public class MyEntity {
    @Ignore
    int field;    
}

Logging

You can log all SQL queries from entities managers:

userEntityManager.logQueries((query, datas) -> Log.d(TAG, query) }

Migration

To handle schema migration, just add @Migration(newVersion) in a static method, then describe the modifications:

public class DatabaseMigration {

    @Migration(2)
    public static void migrateTo2(Migrator migrator) {
        migrator.update("User")
                .removeField("age")
                .renameTo("Man");
    }

    @Migration(3)
    public static void migrateTo3(Migrator migrator) {
        migrator.update("Man")
                .addField("birth", ColumnType.Primitive.Int);
    }
    
    @Migration(4)
    public static void migrateTo4(Migrator migrator) {
        migrator.addTable(migrator.createModel("Woman")
                .field("name", ColumnType.Primitive.String)
                .build());
    }
}

Migration isn't yet capable of:

  • changing type of field
  • adding/modifying One To One
  • adding/modifying One To Many
  • handling collections/arrays

Download

Android app on Google Play

Buy Me a Coffee at ko-fi.com

Download

buildscript {
  dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
  }
}

apply plugin: 'com.neenbedankt.android-apt'

dependencies {
  compile 'fr.xebia.android.freezer:freezer:2.0.6'
  provided 'fr.xebia.android.freezer:freezer-annotations:2.0.6'
  apt 'fr.xebia.android.freezer:freezer-compiler:2.0.6'
}

Changelog

1.0.1

Introduced Migration Engine.

1.0.2

  • Support long & double
  • Support arrays
  • Improved QueryBuilder
  • Refactored cursors helpers

1.0.3

  • Support dates
  • Added unit tests
  • Fixed one to many

1.0.4

  • Added @Id & @Ignore

1.0.5

  • Model update

2.0.0

  • Async API
  • Support Observables
  • Added @DatabaseName

2.0.1

  • Limit

2.0.2

  • Added query.in(...values...)

2.0.3

  • Freezer.onCreate is no longer dynamic

2.0.5

  • Improved performace for batch add & update (thanks to graphee-gabriel)

2.0.6

  • Add or update object if same @Id onadd, addAll`

2.1.0

  • Added RxJava2 support

A project initiated by Xebia

This project was first developed by Xebia and has been open-sourced since. We will continue working on it. We encourage the community to contribute to the project by opening tickets and/or pull requests.

logo xebia

Android app on Google Play Android app on Google Play

License

Copyright 2015 Xebia, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
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].