-
Notifications
You must be signed in to change notification settings - Fork 0
Mapping to Objects
ZorT edited this page Apr 18, 2023
·
11 revisions
That's right! You can save and load objects from database using queries and map them automatically to Java objects. This section will show you how to do that.
public class User {
@PrimaryKey
private String firstname;
private String lastname;
public User(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
}- No args constructor (Recommended!)
- All args constructor
connection.buildEntitySchema("users", User.class);Migrations are planned feature
public void saveUser() {
User user = new User("John", "Doe");
QueryResult result = connection.save("users", user);
}
public void loadUser() {
User user = connection.select()
.from("users")
.where().isEqual("firstname", "John")
.obtainOne(User.class)
.orElse(null);
}Now, we present to you proxy gates! Please head to Proxy Gates to learn how to create repositories for performing queries.