Skip to content
This repository has been archived by the owner on Aug 6, 2022. It is now read-only.

πŸ€ Simple, Fast and easy to implement ORM for most popular databases

License

Notifications You must be signed in to change notification settings

Szczurowsky-playground/RatORM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RatORM

Simple, Fast and easy to implement ORM for most popular databases

Build with java It works why?

Status:

Branch Tests Code Quality
master CircleCI CodeFactor Grade

Usefull links

Helpful links:

List of databases

  • MongoDB
  • MySQL (Soon)
  • MariaDB (Soon)
  • PostgreSQL (Soon)
  • SQLite (Soon)

MineCodes Repository (Maven or Gradle) ️

<repository>
  <id>minecodes-repository</id>
  <url>https://repository.minecodes.pl/releases</url>
</repository>
maven { url "https://repository.minecodes.pl/releases" }

Dependencies (Maven or Gradle)

Framework Core

<dependency>
    <groupId>pl.szczurowsky</groupId>
    <artifactId>rat-orm-core</artifactId>
    <version>1.4.0</version>
</dependency>
implementation 'pl.szczurowsky:rat-orm-core:1.4.0'

Database

<dependency>
    <groupId>pl.szczurowsky</groupId>
    <artifactId>rat-orm-type</artifactId>
    <version>1.4.0</version>
</dependency>
implementation 'pl.szczurowsky:rat-orm-type:1.4.0'

Usage

More advance examples in docs

Connect

By credentials
public class Example {
    
    Database database;
    
    public void connect() {
        // Replace MongoDB() with your database type
        this.database = new MongoDB();
        Map<String, String> credentials = new HashMap<>();
        credentials.put("name", "name of db");
        credentials.put("username", "username");
        credentials.put("password", "password");
        credentials.put("host", "DNS or IP");
        credentials.put("port", "port");
        this.database.connect(credentials);
    }
    
}
By URI
public class Example {
    
    Database database;
    
    public void connect() {
        // Replace MongoDB() with your database type
        this.database = new MongoDB();
        this.database.connect("URI String");
    }
    
}

Create model

Model class
@Model(tableName="example-table")
public class ExampleModel extends BaseModel {
    @ModelField(isPrimaryKey = true)
    int id;
    @ModelField
    String username = "default value";
    // Custom table name
    @ModelField(name="test")
    String oneName;
}
Initialization of model
public class Example {
    
    Database database;
    
    public void connect() {
        // Replace MongoDB() with your database type
        this.database = new MongoDB();
        this.database.connect("URI String");
        this.database.initModel(Arrays.asList(
                ExampleModel.class
        ));
    }
    
}

Read model(s)

Every model
public class Example {
    
    Database database;
    
    public void connect() {
        // Replace MongoDB() with your database type
        this.database = new MongoDB();
        this.database.connect("URI String");
        this.database.initModel(Arrays.asList(
                ExampleModel.class
        ));
        this.database.fetchAll(ExampleModel.class);
    }
    
}
Exact model(s)
public class Example {
    
    Database database;
    
    public void connect() {
        // Replace MongoDB() with your database type
        this.database = new MongoDB();
        this.database.connect("URI String");
        this.database.initModel(Arrays.asList(
                ExampleModel.class
        ));
        this.database.fetchMatching(ExampleModel.class, "Key", "Value");
    }
    
}

Save model

Save one
public class Example {
    
    Database database;
    
    public void connect() {
        // Replace MongoDB() with your database type
        this.database = new MongoDB();
        this.database.connect("URI String");
        this.database.initModel(Arrays.asList(
                ExampleModel.class
        ));
        ExampleModel exampleModel = new ExampleModel();
        this.database.save(exampleModel, ExampleModel.class);
    }
    
}

About

πŸ€ Simple, Fast and easy to implement ORM for most popular databases

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages