0

I'm making an application that requires an online and local database. I have a lot working, but I have a list of things I need for "setup" for each database table.

I'm using SQLDelight and so I need a class (for each database table) like this

public abstract class Db{TableName} implements {TableName}Model {
    public static final {TableName}Model.Factory<Db{TableName}> FACTORY = new {TableName}Model.Factory<>(AutoValue_Db{TableName}::new);
    public static final RowMapper<Db{TableName} MAPPER = FACTORY.select_allMapper();

where {TableName} should be replaced by the name of each table.

To me it just looks like a for loop that would run through the filenames of every .sq file I have (these initialize my database tables and {Tablename}Model classes - the latter through SQLDelight), but I do not know how to implement this.

  • I'm willing to copy and paste this and find+replace {TableName} with the necessary tablename for every tablename, I just figured this would become a pain with a large number of tables so there may be a better solution – Nathan Free Feb 21 '17 at 00:39
  • you would need to write a gradle plugin that did this for you. SQLDelight itself is a gradle plugin that accepts .sq files as input and creates .java files so you could look at the source code. – Anstrong Feb 21 '17 at 12:33

0 Answers0