Branch | Tests | Code Quality |
---|---|---|
master |
Helpful links:
- MongoDB
- MySQL (Soon)
- MariaDB (Soon)
- PostgreSQL (Soon)
- SQLite (Soon)
<repository>
<id>minecodes-repository</id>
<url>https://repository.minecodes.pl/releases</url>
</repository>
maven { url "https://repository.minecodes.pl/releases" }
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'
More advance examples in docs
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");
}
}
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
));
}
}
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 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);
}
}