SqlDelight 没有为 SQL 语句生成 SQL 查询字符串
SqlDelight not generating SQL Query String for SQL Statement
在SqlDelight documentation中的例子中,SqlDelight从HockeyPlayer.sq
文件中生成的HockeyPlayerModel
是在抽象class中实现的public abstract class HockeyPlayer implements HockeyPlayerModel
在此 class 中,字符串 SELECT_ALL_INFO
作为查询传入 db.rawQuery(SELECT_ALL_INFO, new String[0])
。字符串 SELECT_ALL_INFO
是由 HockeyPlayer.sq
中的 select_all_info
语句生成的。但是,在我的情况下,我的语句不会生成字符串。这是为什么?
我的声明
names_for_groups:
SELECT DISTINCT name, exercise_set_group FROM exercise_set JOIN exercises
USING (exercise_id) WHERE workout_FK = ? ORDER BY exercise_set_group ASC ;
我对 ExerciseSetModel
的实现由 SqlDelight
生成
@AutoValue
public abstract class DbExerciseSet implements ExerciseSetModel, DbItem {
public static final Factory<DbExerciseSet> FACTORY = new Factory<>(AutoValue_DbExerciseSet::new);
public static final RowMapper<DbExerciseSet> MAPPER = FACTORY.select_allMapper();
public static final RowMapper<NamesForGroups> NAMES_FOR_GROUPS_MAPPER =
FACTORY.names_for_groupsMapper(AutoValue_DbExerciseSet_NamesForGroups::new);
public List<NamesForGroups> namesForGroups(SQLiteDatabase db) {
List<NamesForGroups> namesForGroupsList= new ArrayList<>();
Cursor cursor = db.rawQuery(NAMES_FOR_GROUPS, new String[0]);
while (cursor.moveToNext() && NAMES_FOR_GROUPS_MAPPER.map(cursor) != null) {
//NamesForGroups namesForGroups = NAMES_FOR_GROUPS_MAPPER.map(cursor);
namesForGroupsList.add(NAMES_FOR_GROUPS_MAPPER.map(cursor));
}
return namesForGroupsList;
}
@AutoValue
public abstract static class NamesForGroups implements Names_for_groupsModel {}
@AutoValue
public abstract static class Exercises implements ExerciseModel {}
}
明确一点,变量引用NAMES_FOR_GROUPS在行db.rawQuery(NAMES_FOR_GROUPS, new String[0])
中找不到
文档需要更新,我来更新。我们不再在 SQLDelight 0.6.+ 中生成字符串,取而代之的是工厂上有一个方法 returns 一个 SQLDelightStatement
用于查询:
public List<NamesForGroups> namesForGroups(SQLiteDatabase db) {
List<NamesForGroups> namesForGroupsList= new ArrayList<>();
SQLDelightStatement query = FACTORY.name_for_groups();
Cursor cursor = db.rawQuery(query.statement, query.args);
while (cursor.moveToNext() && NAMES_FOR_GROUPS_MAPPER.map(cursor) != null) {
//NamesForGroups namesForGroups = NAMES_FOR_GROUPS_MAPPER.map(cursor);
namesForGroupsList.add(NAMES_FOR_GROUPS_MAPPER.map(cursor));
}
return namesForGroupsList;
}
在SqlDelight documentation中的例子中,SqlDelight从HockeyPlayer.sq
文件中生成的HockeyPlayerModel
是在抽象class中实现的public abstract class HockeyPlayer implements HockeyPlayerModel
在此 class 中,字符串 SELECT_ALL_INFO
作为查询传入 db.rawQuery(SELECT_ALL_INFO, new String[0])
。字符串 SELECT_ALL_INFO
是由 HockeyPlayer.sq
中的 select_all_info
语句生成的。但是,在我的情况下,我的语句不会生成字符串。这是为什么?
我的声明
names_for_groups:
SELECT DISTINCT name, exercise_set_group FROM exercise_set JOIN exercises
USING (exercise_id) WHERE workout_FK = ? ORDER BY exercise_set_group ASC ;
我对 ExerciseSetModel
的实现由 SqlDelight
@AutoValue
public abstract class DbExerciseSet implements ExerciseSetModel, DbItem {
public static final Factory<DbExerciseSet> FACTORY = new Factory<>(AutoValue_DbExerciseSet::new);
public static final RowMapper<DbExerciseSet> MAPPER = FACTORY.select_allMapper();
public static final RowMapper<NamesForGroups> NAMES_FOR_GROUPS_MAPPER =
FACTORY.names_for_groupsMapper(AutoValue_DbExerciseSet_NamesForGroups::new);
public List<NamesForGroups> namesForGroups(SQLiteDatabase db) {
List<NamesForGroups> namesForGroupsList= new ArrayList<>();
Cursor cursor = db.rawQuery(NAMES_FOR_GROUPS, new String[0]);
while (cursor.moveToNext() && NAMES_FOR_GROUPS_MAPPER.map(cursor) != null) {
//NamesForGroups namesForGroups = NAMES_FOR_GROUPS_MAPPER.map(cursor);
namesForGroupsList.add(NAMES_FOR_GROUPS_MAPPER.map(cursor));
}
return namesForGroupsList;
}
@AutoValue
public abstract static class NamesForGroups implements Names_for_groupsModel {}
@AutoValue
public abstract static class Exercises implements ExerciseModel {}
}
明确一点,变量引用NAMES_FOR_GROUPS在行db.rawQuery(NAMES_FOR_GROUPS, new String[0])
文档需要更新,我来更新。我们不再在 SQLDelight 0.6.+ 中生成字符串,取而代之的是工厂上有一个方法 returns 一个 SQLDelightStatement
用于查询:
public List<NamesForGroups> namesForGroups(SQLiteDatabase db) {
List<NamesForGroups> namesForGroupsList= new ArrayList<>();
SQLDelightStatement query = FACTORY.name_for_groups();
Cursor cursor = db.rawQuery(query.statement, query.args);
while (cursor.moveToNext() && NAMES_FOR_GROUPS_MAPPER.map(cursor) != null) {
//NamesForGroups namesForGroups = NAMES_FOR_GROUPS_MAPPER.map(cursor);
namesForGroupsList.add(NAMES_FOR_GROUPS_MAPPER.map(cursor));
}
return namesForGroupsList;
}