Giter Site home page Giter Site logo

rathansrk / android-sqlite-model-generator-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sromku/android-sqlite-model-generator-plugin

0.0 2.0 0.0 782 KB

Eclipse plugin - Generate SQLite model for Android based on JSON schema object

Java 100.00%

android-sqlite-model-generator-plugin's Introduction

SQLite Model Generator

Eclipse plugin - Generate SQLite model for Android based on JSON schema file

Usage of the plugin

1. Install the plugin

Update site: http://romkuapps.com/Apps/SQLite/update

2. Create JSON file that describes your sqlite schema.

  • Schema has name and tables
  • table has name, description and columns
  • column has name and columnType
  • columnType can be TEXT or INTEGER only

Example: Two tables: STUDENT and COURSE

{
  "name": "SQL_PRIVATE_DB",
  "tables": [
    {
      "name": "STUDENT",
      "description": "Student details",
      "columns": [
        {
          "name": "FIRSTNAME",
          "columnType": "TEXT"
        },
        {
          "name": "LASTNAME",
          "columnType": "TEXT"
        },
        {
          "name": "AGE",
          "columnType": "INTEGER"
        }
      ]
    },
    {
      "name": "COURSE",
      "description": "Course details",
      "columns": [
        {
          "name": "NAME",
          "columnType": "TEXT"
        },
        {
          "name": "COURSENUMBER",
          "columnType": "INTEGER"
        },
        {
          "name": "DESCRIPTION",
          "columnType": "TEXT"
        },
        {
          "name": "POINTS",
          "columnType": "INTEGER"
        }
      ]
    }
  ]
}

3. Right click on the file -> 'Generate SQLite Model...' Screenshot

Screenshot

4. Refresh the project

Screenshot

Generated Code

Entities

Each table is converted to Java entity and is generated under 'entities' package

| - entities

Actions

Each entity can be creates, updated, deleted or retrieved from the database. The support for CRUD actions is located under 'actions' package

  | - actions
	  | - create
	  | - delete
	  | - read
	  | - update

Model

The entry point for all operations above SQLite database are done via Model.java class, which is located under 'model' package

	| - model	

Usage

Create

For each defined table in the JSON file you can create a new entity which will be saved in the SQLite table

	Student student = new Student();
	student.setFirstname("John");
	student.setLastname("Smith");
	student.setAge(30);
		
	Model model = Model.getInstance(context);
	model.createStudent(student);

Retrieve

For each defined table in the JSON file you can retrieve all entities from that SQLite table

	Model model = Model.getInstance(context);
	List<Student> students = model.readStudent();

Update

For each defined table in the JSON file you can update existing entity from the SQLite table

	student.setAge(31);
	
	Model model = Model.getInstance(context);
	model.updateStudent(student);

Delete

For each defined table in the JSON file you can delete existing entity from the SQLite table

	Model model = Model.getInstance(context);
	model.deleteStudent(student);

How it works

  • The first time the singleton instance of the model is created Model model = Model.getInstance(context), all the SQLite database content is loaded into the memory.
  • Each of CRUD commands works directly with the cached data and SQLite database. For example, model.update...(Object object) will update the entity in the memory and then update the raw in the database. Thus, the database is always synced.

android-sqlite-model-generator-plugin's People

Contributors

sromku avatar

Watchers

 avatar  avatar

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.