Working With Non Objects From The Database - njkremer/SqliteORM GitHub Wiki

The concept here is when you want to select a subset of the columns in a table, so you're not exactly working with a POJO.

This also affords you the ability to do "functions" on columns as well, such as SQLite Date And Time functions.

The way this is done is by leveraging ColumnExpressions

Given the following user class:

public class User {
    @AutoIncrement
    @PrimaryKey
    private long id;
    private String name;
    private String password;
    
    @OneToMany("userId")
    private List<Thing> things;

    // Getters and Setters would be here
    ...
}

If you want to say get just the name and password instead of a list of the whole user objects you could do the following:

List<Map<String, Object>> map = SqlStatement.select(User.class).getColumns(
    new ColumnExpression().column("name").as("username").column("id").as("userid")
);

The from there you'll get a list Maps of all the users in the database where the map is of column name to value. Meaning, if you want to get the first user's username/userid set you'd do the following:

Map<String, Object> firstUsersInfo = map.get(0);
String userName = (String) firstUsersInfo.get("username");
long userId = (Long) firstUsersInfo.get("userid");

So here you can see that the returned map is not typed and you'll need to cast things to the expected types. As mentioned above, the most useful thing this could be used for is to use SQLite functions.

⚠️ **GitHub.com Fallback** ⚠️