Giter Club home page Giter Club logo

pultusorm's Introduction

PultusORM

A Sqlite ORM library for Kotlin, Java & Android.

Status : Active
Version : v1.7

Features

Currently implemented:

  • Insert
  • Retrieve
  • Update
  • Delete
  • Drop

Usages

In your build file add

Gradle
allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

And

dependencies {
    compile 'ninja.sakib:PultusORM:v1.7'
}
Maven
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
	</repository>
</repositories>

And

<dependency>
    <groupId>ninja.sakib</groupId>
    <artifactId>PultusORM</artifactId>
    <version>v1.7</version>
</dependency>

In case you need jar download is available here .

More option can be found here.

Examples

Open database connection
In Kotlin,
val pultusORM: PultusORM = PultusORM("test.db", "/Users/s4kib/")
val pultusORM: PultusORM = PultusORM("test.db")    // DB will take place in user.home directory

In Android (Kotlin),
val appPath: String = getApplicationContext().getFilesDir().getAbsolutePath()  // Output : /data/data/application_package_name/files/
val pultusORM: PultusORM = PultusORM("test.db", appPath)
In Java,
PultusORM orm = new PultusORM("test.db", "/Users/s4kib/")
PultusORM orm = new PultusORM("test.db", )  // DB will take place in user.home directory

In Android (Java),
String appPath = getApplicationContext().getFilesDir().getAbsolutePath()  // Output : /data/data/application_package_name/files/
val orm = new PultusORM("test.db", appPath)
Insert value
class Student {
    @PrimaryKey
    @AutoIncrement
    var studentId: Int = 0
    var name: String? = null
    var department: String? = null
    var cgpa: Double = 0.0
    var dateOfBirth: java.util.Date? = null
    @Ignore
    var section: String? = null
}

val student: Student = Student()
student.name = "Sakib Sayem"
student.department = "CSE"
student.cgpa = 2.3
student.dateOfBirth = Date()
pultusORM.save(student)
pultusORM.close()
Retrieve Values
val students = pultusORM.find(Student())
for (it in students) {
    val student = it as Student
    println(student.studentId)
    println(student.name)
    println(student.department)
    println(student.cgpa)
    println(student.dateOfBirth)
    println()
}
Result
1
Sakib Sayem
CSE
2.3
Wed Sep 27 23:21:52 BDT 2017
Retrieve values based on condition
val condition: PultusORMCondition = PultusORMCondition.Builder()
            .eq("name", "sakib")
            .and()
            .greaterEq("cgpa", 18)
            .or()
            .startsWith("name", "sami")
            .sort("name", PultusORMQuery.Sort.DESCENDING)
            .sort("department", PultusORMQuery.Sort.ASCENDING)
            .build()

val students = pultusORM.find(Student(), condition)
for (it in students) {
    val student = it as Student
    println("${student.studentId}")
    println("${student.name}")
}
Update value
// values will be updated based on this condition
val condition: PultusORMCondition = PultusORMCondition.Builder()
            .eq("name", "Sakib")
            .build()

val updater: PultusORMUpdater = PultusORMUpdater.Builder()
            .set("name", "Sayan Nur")
            .condition(condition)   // condition is optional
            .build()

pultusORM.update(Student(), updater)
Delete values
pultusORM.delete(Student())
Drop Table
pultusORM.drop(Student())

Check out more examples & API docs here


Note

Tables will be created on fly if not exists using class name and columns based on class fields.
Currently supported types:

  • String
  • Int
  • Long
  • Float
  • Double
  • Boolean
  • Date (java.util)

Autoincrement annotated fields values will be skipped as that will be handled by sqlite.

License

Copyright © Sakib Sami

Distributed under MIT license

Patreon Me !!!

If you want to support this project Patreon Me!

pultusorm's People

Contributors

s4kibs4mi avatar thesabbir avatar bigman212 avatar

Watchers

James Cloos 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.