Advanced Usage - njkremer/SqliteORM GitHub Wiki

Slightly More Advanced Usage

For slightly more "advanced" usage, you can specify two different types of Annotations on your POJO.

  • @PrimaryKey - This annotation is to be used on a field of your POJO. It should be put on the field that would correlate to the primary key of the table in the database. It's useful for things like doing an update/delete without specifying a "where" clause (See JavaDoc API for more info)
  • @AutoIncrement - This should be specified on any database columns that are being auto-incremented by the database, so that we know to not specify anything for that field when inserting and let the database handle it.

Example:

public class User {
    @AutoIncrement
    @PrimaryKey
    private long id;
    private String name;
    private String password;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}

Which would map to a table named user that looks like:

column name type PK?
id auto incremented int yes
name text no
password text no
⚠️ **GitHub.com Fallback** ⚠️