Code Monkey home page Code Monkey logo

myorm's Introduction

MyORM

Github Package Github Wiki

A simple ORM(Object Relational Mapping) for Java.

Quck Start

Install

Add this text to your pom.xml

<dependency>
    <groupId>com.wangtingzheng</groupId>
    <artifactId>myorm</artifactId>
    <version>1.0.6</version>
</dependency>

The latest version can be check here.

Define a table

This code will create a table named MyTable which has two item: username and password. The username is a 100 length varchar and it is primary key, the password is same but it is not primary key.

@OrmTable
public class MyTable  {
    @OrmItem(type = ItemTypeEnum.VARCHAR, length = 100, isPrimaryKey = true)
    private String username;

    @OrmItem(type = ItemTypeEnum.VARCHAR, length = 100)
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

Define a database

This code will define a database which includes one table named MyTable. MyOrm can use SQLITE Driver to connect database in 123.456.789.123:3306 use a account called "myuser". When connect established, MyOrm will use database called test, the server timezone is +8:00.

@OrmDatabase(type = DatabaseTypeEnum.SQLITE,host = "123.456.789.123:3306",username = "myuser",password = "mypassword",openDatabase = "test",serverTimezone = "+8:00")
public class MyDatabase {
    @OrmTable()
    public MyTable myTable;

}

Add a record

This code will add a record to table named "MyTable" in database "Mydatabse".

DatabaseApt myDatabase = new DatabaseApt(MyDatabase.class);  //new database annotation process tool
TableApt myTable = new myDatabase.newInstance(MyTable.class ); //get table annotation process tool
MyTable record = new MyTable("wangtingzheng","iloveMyOrm");  //new a record obejct
myDatabase.create(); //create database if not existed
myTable.create(); //create table if not existed
if(myTable.add(record)){  //if add record successfully
    System.out.println("Record has been add to MyTable in Mydatabase.");
}
else{
    System.out.println("Add failed."); 
}

Wiki

More detail can be saw in wiki:

Todo

  • Support more databases
  • Support sql language DIY
  • Improve performance
  • Support more sql data type

myorm's People

Contributors

wangtingzheng avatar

Watchers

 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.