Você está na página 1de 7

SimpLite (/details/1/4900)

 4 (https://github.com/idoamram/SimpLite/stargazers?utm_source=android-

arsenal.com&utm_medium=referral&utm_campaign=4900) 2

(https://github.com/idoamram/SimpLite/watchers?utm_source=android-

arsenal.com&utm_medium=referral&utm_campaign=4900)  3

(https://github.com/idoamram/SimpLite/network?utm_source=android-

arsenal.com&utm_medium=referral&utm_campaign=4900)  0

(https://github.com/idoamram/SimpLite/issues?utm_source=android-

arsenal.com&utm_medium=referral&utm_campaign=4900)

 (https://facebook.com/sharer.php?
General u=https://android-
Category
arsenal.com/details/1/4900)
Free (/free)

Tag
 (https://twitter.com/intent/twe
arsenal.com/details/1/4900&text=The%20An
ORM (/tag/69)

License %20ORM%20-%20SimpLite
Apache License, Version 2.0 (http://opensource.org/licenses/Apache-2.0?utm_source=android-arsenal.co

 (http://news.ycombinator.com/submitlink
m&utm_medium=referral&utm_campaign=4900)

arsenal.com/details/1/4900&t=The%20Andro
Min SDK
16 (Android 4.1 Jelly Bean) (/api?level=16)

Registered
%20ORM%
Dec 19, 2016

Favorites
 (https://plus.google.com/share?
1 url=https://android-
Link arsenal.com/details/1/4900)
https://github.com/idoamram/SimpLite/ (https://github.com/idoamram/SimpLite/?utm_source=android-arse

 (https://reddit.com/subm
nal.com&utm_medium=referral&utm_campaign=4900)

arsenal.com/details/1/4900&title=The%20An
See also
Orma (/details/1/2875)
Torch (/details/1/338) %20OR
DBFlow (/details/1/1134)
Ollie (/details/1/1037)
Storm (/details/1/5559)

Additional

Language
Java

Version
N/A (https://github.com/idoamram/SimpLite/releases?utm_source=android-arsenal.com&utm_medium=re
ferral&utm_campaign=4900)

Created
Dec 3, 2016

Updated
Dec 26, 2016 (Retired)

Owner
idoamram (/user/idoamram)

Contributor
1 (https://github.com/idoamram/SimpLite/graphs/contributors?utm_source=android-arsenal.com&utm_me
dium=referral&utm_campaign=4900)

Activity

Badge
 Generate

Download
 Source code

Commercial
 

Learn techniques for


Mapping SQL mapping and attening
NoSQL to a tabular
to NoSQL interface.

SimpLite

###SQLite ORM for Android. Simple and easy-to-use.

Usage

###1. Add a dependency to your build.gradle file

compile 'com.simplite:simplite-orm:0.9.4'

###2. Create an Entity class

Add inheritance from the DBObject class


Add fields
For each field, create getters and setters
The get;set methods must named accordingly to the fields names
For exmaple, if you have firstName field, you'll have a getFirstName getter and a
setFirstName setter
Add @Entity annotation to your class (MUST)

@Entity(tableName = "my_cool_entity_table_name")
public class MyCoolEntity extends DBObject

Add @PrimaryKey to your primary key field (MUST)


@PrimaryKey(columnName = "my_pk_column_name")
private String id;

Add Other columns annotations (See the full explanation below)


Column - a regular column - int age
ForeignKey - when the field is an instance of other entity - Car myCar
ForeignKeyArray - when the field is an ArrayList of instances of other entity -
ArrayList<Car> myCars

###3. Add meta-data to your manifest Name | Type | Value | Default value ---- | ---- | ----- | ------------
- DATABASE_NAME | String | <DATABASE_FILE_NAME> | default_db DATABASE_VERSION |
Number | <CURRENT_DATABASE_VERSION> | 1 CONFIG_CLASS | String |
<FULL_CONIFGURATION_CLASS_NAME> | null ENTITIES_CLASSES_NAME | String array |
<FULL_CLASS_NAMES_ARRAY> | []

#####DATABASE_NAME Your database file name

<meta-data android:name="DATABASE_NAME" android:value="<DATABASE_NAME>" />

Exmaple

<meta-data android:name="DATABASE_NAME" android:value="my_great_db" />

#####DATABASE_VERSION Changing this value will cause database upgrade. When


onUpgrade method called, all tables will drop (DROP TABLE) and recreates in onCreate. ALL OF
YOUR DATA WILL GET LOST (See CONFIG_CLASS).

<meta-data android:name="DATABASE_VERSION" android:value="<DATABASE_VERSION>" />

Example

<meta-data android:name="DATABASE_VERSION" android:value="6" />

#####CONFIG_CLASS You MUST specify the FULL name, including all packages. The
configuration class MUST implement the SimpLiteConfiguration interface. It has
beforeOnCreate, afterOnCreate ,beforeOnUpgrade, afterOnUpgrade. For saving your data during
upgrade, hold it on beforeOnUpgrade, and insert it on afterOnCreate.

<meta-data android:name="CONFIG_CLASS" android:value="<FULL_CLASS_NAME>" />

Example
<meta-data android:name="CONFIG_CLASS" android:value="com.simplite.example.utils.LocalDBCon

#####ENTITIES_CLASSES_NAME The FULL (include all packages) name of each class that
represent an entity (table in the database). An Entity MUST extend from DBObject class. The
entities should separate with a coma

<meta-data android:name="ENTITIES_CLASSES_NAME" android:value="com.simplite.example.entitie


com.simplite.example.entities.EntityTwo,com.simplite.example.entities.EntityThr

###Annotations Usage

#####@Entity ######For a class that represents an entity (table) in the database Method |
Expected Value ------ | -------------- tableName | The name of the table that this entity represents

#####@PrimaryKey ######For a field that is a primary key in its table. Method | Expected Value --
---- | -------------- columnName | The name of the column options | Options to add to the column, like
AUTOINCREMENT or UNIQUE

#####@Column ######For any field that is a regular column - not primary or foreign key Method |
Expected Value ------ | -------------- name | The name of the column options | Options to add to the
column, like AUTOINCREMENT or UNIQUE

#####@ForeignKey ######For any field that is an instance of other entity Method | Expected
Value ------ | -------------- valueColumnName | The name of the column in the current table
fkColumnName | The name of the column in the foreign table entityClass | The foreign entity
class options | Options to add to the column, like AUTOINCREMENT or UNIQUE

#####@ForeignKeyArray ######For any field that is an ArrayList of instances of other entity


Method | Expected Value ------ | -------------- valueColumnName | The name of the column in the
current table fkColumnName | The name of the column in the foreign table entityClass | The
foreign entity class options | Options to add to the column, like AUTOINCREMENT or UNIQUE

CRUD

Person person = new Person(context);

#####Create

person.create()

#####Delete
person.delete()

#####Update

person.save()

#####Read

findAll
findAllByColumn
findOne
findById
query
rawQuery
count
countByColumn
getAverageByColumn

#####CRUD in background Each CRUD method have another method that called
[methodName]+"InBackground"(For example: createInBackground), that execute the original
method in an AsyncTask.

###SQL helpers Return string that is a CREATE TABLE command for a class.

getCreateTableCommand

Return string that is an INSERT command for a class instance, including the current fields values.

getInsertCommand

Return string that is an UPDATE command for a class instance, including the current fields
values.

getUpdateCommand

###Please feel more than FREE to contact me and give a feedback, i want to improve the library
and make it better for you. ###ido.movieditor@gmail.com (mailto:ido.movieditor@gmail.com)
Follow us on Twitter (https://twitter.com/Android_Arsenal?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=4900)

Read us in Telegram (https://telegram.me/AndroidArsenal?utm_source=android-


arsenal.com&utm_medium=referral&utm_campaign=4900)

Get Android app on Google Play (https://play.google.com/store/apps/details?


id=com.android_arsenal.androidarsenal&utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=4900)

Stay informed with Pushbullet (https://www.pushbullet.com/channel?tag=android_arsenal&utm_source=android-


arsenal.com&utm_medium=referral&utm_campaign=4900)

Created by Vladislav Bauer (https://github.com/vbauer?utm_source=android-


arsenal.com&utm_medium=referral&utm_campaign=4900)
 (https://twitter.com/BauerVlad?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=4900)
 (https://www.linkedin.com/in/vladislavbauer?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=4900)
 (https://www.paypal.me/VladislavBauer?utm_source=android-
arsenal.com&utm_medium=referral&utm_campaign=4900)
© 2014-2018 - Android Arsenal (/) | Privacy (/privacy)

Você também pode gostar