Giter VIP home page Giter VIP logo

sqlite-database-model's Introduction

SQLite-Database-Model

SQLite Database Model is a super lightweight yet powerful Object Relational Mapping (ORM) Framework for Java and SQLite 3.

SQLite Database Model weighs in at under 50KB** yet offers a powerful feature set including…

Automatic database generation

Database tables can be created from or mapped to any Java class without the need for inheritance or interface implementation.

By simply decorating your classes properties with a few key annotations and adding them to the model, SQLite Database Model can generate your enitre SQLite 3 database including primary keys, foreign keys relationships, unique constraints and more all without writing a single line of SQL.

Versatile, reflection powered CRUD methods

Creating, querying, updating and deleting records in your database can be done with just a few simple lines of code via the SQLite Database Model API.

For example, to query a database table containing Employee data for all employees that work in HR and earn a salary greater than or equal to 30000 is as simple as:

    List<Employee> employees = db.getObjectModel(Employee.class)
        .getAll("department = ? AND salary >= ?", Department.HR, 30000);

To update an employee’s salary with a 15% increase, all that we’d need to do is update the object property and pass the employee as a parameter to the update(T t) method of the Employee model…

    employee.setSalary(employee.getSalary() * 1.15);
    employeeModel.update(employee);

Relationship management

Foreign key constraints and relationships between objects can be defined by simply marking the appropriate property with the @ForeignKey annotation.

With relationships defined, SQLite Database Model can cascade insert, update & delete operations and automatically retrieve any related objects when the parent object is retrieved from the database.

For example, SQLite Database Model could be configured to automatically fill an employee’s pencils list with the employees pencils from the pencil table when the employee object is inflated as a result of a database query.

Furthermore, adding a new pencil to the employee’s pencils list and then updating the employee would automatically insert the new pencil into the SQLite 3 database’s pencil table and deleting the employee could also automatically delete the employees pencils.

Comprehensive type support

Not only does SQLite Database Model support a comprehensive list of primitive types out of the box, but with ease of extensibility as a primary design concern, you can easily extend your model to map any complex type/java object to a custom table column and SQLite Database Model will persist and re-construct the complex type for you.

  • String
  • boolean/Boolean
  • byte/Byte/byte[]
  • short/Short
  • int/Integer
  • long/Long
  • float/Float
  • double/Double
  • Date/Calendar
  • enum – any enum can be mapped out of the box
  • Custom column types – map complex types to a logical primitive value

**The size of the SQLite Database Model library is under 50KB. However, if you would like to use the library with JDBC you will need to include the Xerial SQLite JDBC driver which is considerably larger(~3000KB). The Android version does not require a driver as it makes use of Android’s internal SQLite APIs.

sqlite-database-model's People

Contributors

sheldonneilson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sqlite-database-model's Issues

Crash in my Android app

java.lang.RuntimeException:
at android.app.ActivityThread.performPauseActivityIfNeeded (ActivityThread.java:4137)
at android.app.ActivityThread.performPauseActivity (ActivityThread.java:4103)
at android.app.ActivityThread.performPauseActivity (ActivityThread.java:4066)
at android.app.ActivityThread.handlePauseActivity (ActivityThread.java:4024)
at android.app.ActivityThread.-wrap18 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1647)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6692)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException:
at java.lang.reflect.Field.get (Native Method)
at za.co.neilson.sqlite.orm.ObjectModel.setColumnValue (ObjectModel.java:470)
at za.co.neilson.sqlite.orm.ObjectModel.update (ObjectModel.java:1094)

at elihai.com.a100blaces.DAL.update (DAL.java:68)
at elihai.com.a100blaces.MainActivity.onPause (MainActivity.java:88)
at android.app.Activity.performPause (Activity.java:7103)
at android.app.Instrumentation.callActivityOnPause (Instrumentation.java:1330)
at android.app.ActivityThread.performPauseActivityIfNeeded (ActivityThread.java:4126)

I'll be happy to know what I did worng :)

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.