SimpLite


Source link: https://github.com/idoamram/SimpLite/

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.LocalDBConfiguration" /> 

#####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.entities.EntityOne,

 com.simplite.example.entities.EntityTwo,com.simplite.example.entities.EntityThree" /> 

###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. ### [email protected]

Resources

DaVinci is an image downloading and caching library for Android Wear.

jimu Mirror provides live, on-device previews of Android layouts. It also allows you to create realistic prototypes of Android native UI without Java code.

This library provides a BaseBluetoothActivity that you inherit from to easily take care of:

  • Enabling bluetooth
  • Scanning for new devices.
  • Connecting to a device.
  • Receiving data from the device.
  • Sending data to the device.

Just a simple a linked ViewPager.

A modern JSON library for Android and Java.

A custom ViewPager which gives continuous feedback to the user when scrolling.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes