String LOGIN = "login"; String AVATARURL = "avatarUrl"; String CREATE_TABLE = "" + "CREATE TABLE user (\n" + " login TEXT NOT NULL PRIMARY KEY,\n" + " avatarUrl TEXT\n" + ")"; @NonNull String login(); @Nullable String avatarUrl(); interface Creator<T extends UserModel> { T create(@NonNull String login, @Nullable String avatarUrl); } final class Mapper<T extends UserModel> implements RowMapper<T> { private final Factory<T> userModelFactory; public Mapper(Factory<T> userModelFactory) { this.userModelFactory = userModelFactory; } @Override public T map(@NonNull Cursor cursor) { return userModelFactory.creator.create( cursor.getString(0), cursor.isNull(1) ? null : cursor.getString(1) ); } } final class Marshal { protected final ContentValues contentValues = new ContentValues(); Marshal(@Nullable UserModel copy) { if (copy != null) { this.login(copy.login()); this.avatarUrl(copy.avatarUrl()); } } public ContentValues asContentValues() { return contentValues; } public Marshal login(String login) { contentValues.put("login", login); return this; } public Marshal avatarUrl(String avatarUrl) { contentValues.put("avatarUrl", avatarUrl); return this; } } final class Factory<T extends UserModel> { public final Creator<T> creator; public Factory(Creator<T> creator) { this.creator = creator; } /** * @deprecated Use compiled statements (https://github.com/square/sqldelight#compiled-statements) */ @Deprecated public Marshal marshal() { return new Marshal(null); } /** * @deprecated Use compiled statements (https://github.com/square/sqldelight#compiled-statements) */ @Deprecated public Marshal marshal(UserModel copy) { return new Marshal(copy); } public SqlDelightStatement select_user(@NonNull String login) { List<String> args = new ArrayList<String>(); int currentIndex = 1; StringBuilder query = new StringBuilder(); query.append("SELECT *\n" + "FROM user\n" + "WHERE user.login = "); query.append('?').append(currentIndex++); args.add(login); return new SqlDelightStatement(query.toString(), args.toArray(new String[args.size()]), Collections.<String>singleton("user")); } /** * @deprecated Use {@link Insert_user} */ @Deprecated public SqlDelightStatement insert_user(@NonNull String login, @Nullable String avatarUrl) { List<String> args = new ArrayList<String>(); int currentIndex = 1; StringBuilder query = new StringBuilder(); query.append("INSERT INTO user(login, avatarUrl)\n" + "VALUES("); query.append('?').append(currentIndex++); args.add(login); query.append(", "); if (avatarUrl == null) { query.append("null"); } else { query.append('?').append(currentIndex++); args.add(avatarUrl); } query.append(")"); return new SqlDelightStatement(query.toString(), args.toArray(new String[args.size()]), Collections.<String>singleton("user")); } public Mapper<T> select_userMapper() { return new Mapper<T>(this); } } final class Insert_user extends SqlDelightCompiledStatement.Insert { public Insert_user(SQLiteDatabase database) { super("user", database.compileStatement("" + "INSERT INTO user(login, avatarUrl)\n" + "VALUES(?, ?)")); } public interface RepositoryModel { String TABLE_NAME = "repository"; String NAME = "name"; String DESCRIPTION = "description"; String OWNER = "owner"; String CREATE_TABLE = "" + "CREATE TABLE repository (\n" + " name TEXT NOT NULL PRIMARY KEY,\n" + " description TEXT,\n" + " owner TEXT NOT NULL,\n" + " FOREIGN KEY (owner) REFERENCES user(login)\n" + ")"; @NonNull String name(); @Nullable String description(); @NonNull String owner(); interface Select_allModel<T1 extends RepositoryModel, T2 extends UserModel> { @NonNull T1 repository(); @NonNull T2 user(); } interface Select_allCreator<T1 extends RepositoryModel, T2 extends UserModel, T extends Select_allModel<T1, T2>> { T create(@NonNull T1 repository, @NonNull T2 user); } final class Select_allMapper<T1 extends RepositoryModel, T2 extends UserModel, T extends Select_allModel<T1, T2>> implements RowMapper<T> { private final Select_allCreator<T1, T2, T> creator; private final Factory<T1> repositoryModelFactory; private final UserModel.Factory<T2> userModelFactory; public Select_allMapper(Select_allCreator<T1, T2, T> creator, Factory<T1> repositoryModelFactory, UserModel.Factory<T2> userModelFactory) { this.creator = creator; this.repositoryModelFactory = repositoryModelFactory; this.userModelFactory = userModelFactory; } @Override @NonNull public T map(@NonNull Cursor cursor) { return creator.create( repositoryModelFactory.creator.create( cursor.getString(0), cursor.isNull(1) ? null : cursor.getString(1), cursor.getString(2) ), userModelFactory.creator.create( cursor.getString(3), cursor.isNull(4) ? null : cursor.getString(4) ) ); } } interface Creator<T extends RepositoryModel> { T create(@NonNull String name, @Nullable String description, @NonNull String owner); } final class Mapper<T extends RepositoryModel> implements RowMapper<T> { private final Factory<T> repositoryModelFactory; public Mapper(Factory<T> repositoryModelFactory) { this.repositoryModelFactory = repositoryModelFactory; } @Override public T map(@NonNull Cursor cursor) { return repositoryModelFactory.creator.create( cursor.getString(0), cursor.isNull(1) ? null : cursor.getString(1), cursor.getString(2) ); } } final class Marshal { protected final ContentValues contentValues = new ContentValues(); Marshal(@Nullable RepositoryModel copy) { if (copy != null) { this.name(copy.name()); this.description(copy.description()); this.owner(copy.owner()); } } public ContentValues asContentValues() { return contentValues; } public Marshal name(String name) { contentValues.put("name", name); return this; } public Marshal description(String description) { contentValues.put("description", description); return this; } public Marshal owner(String owner) { contentValues.put("owner", owner); return this; } } final class Factory<T extends RepositoryModel> { final class Factory<T extends RepositoryModel> { public final Creator<T> creator; public Factory(Creator<T> creator) { this.creator = creator; } /** * @deprecated Use compiled statements (https://github.com/square/sqldelight#compiled-statements) */ @Deprecated public Marshal marshal() { return new Marshal(null); } /** * @deprecated Use compiled statements (https://github.com/square/sqldelight#compiled-statements) */ @Deprecated public Marshal marshal(RepositoryModel copy) { return new Marshal(copy); } public SqlDelightStatement select_all() { return new SqlDelightStatement("" + "SELECT *\n" + "FROM repository\n" + "JOIN user ON repository.owner = user.login", new String[0], Collections.<String>unmodifiableSet(new LinkedHashSet<String>(Arrays.asList("repository","user")))); } /** * @deprecated Use {@link Insert_reporitory} */ @Deprecated public SqlDelightStatement insert_reporitory(@NonNull String name, @Nullable String description, @NonNull String owner) { List<String> args = new ArrayList<String>(); int currentIndex = 1; StringBuilder query = new StringBuilder(); query.append("INSERT INTO repository(name, description, owner)\n" + "VALUES("); query.append('?').append(currentIndex++); args.add(name); query.append(", "); if (description == null) { query.append("null"); } else { query.append('?').append(currentIndex++); args.add(description); } query.append(", "); query.append('?').append(currentIndex++); args.add(owner); query.append(")"); return new SqlDelightStatement(query.toString(), args.toArray(new String[args.size()]), Collections.<String>singleton("repository")); } public <T2 extends UserModel, R extends Select_allModel<T, T2>> Select_allMapper<T, T2, R> select_allMapper(Select_allCreator<T, T2, R> creator, UserModel.Factory<T2> userModelFactory) { return new Select_allMapper<T, T2, R>(creator, this, userModelFactory); } } final class Insert_reporitory extends SqlDelightCompiledStatement.Insert { public Insert_reporitory(SQLiteDatabase database) { super("repository", database.compileStatement("" + "INSERT INTO repository(name, description, owner)\n" + "VALUES(?, ?, ?)")); } public void bind(@NonNull String name, @Nullable String description, @NonNull String owner) { program.bindString(1, name); if (description == null) { program.bindNull(2); } else { program.bindString(2, description); } program.bindString(3, owner); } } }