shillelagh-processor/src/main/java/shillelagh/internal/TableObject.java
private void emitInsert(JavaWriter javaWriter) throws IOException {
    logger.d("emitInsert");
    String tableName = getTableName();
    javaWriter.beginMethod("void", $$INSERT_OBJECT_FUNCTION, EnumSet.of(PUBLIC, STATIC),
        getTargetClass(), "element", "SQLiteDatabase", "db")
        .emitStatement("ContentValues values = new ContentValues()");
    List<TableColumn> childColumns = Lists.newLinkedList();
    for (TableColumn column : columns) {
      String columnName = column.getColumnName();
      String memberName = column.getMemberName();
      if (column.isBlob() && !column.isByteArray()) {
        javaWriter.emitStatement("values.put(\"%s\", %s(element.%s))", columnName,
            SERIALIZE_FUNCTION, memberName);
      } else if (column.isOneToOne()) {
        javaWriter.emitStatement("%s%s.%s(element.%s, db)", column.getType(), $$SUFFIX,
            INSERT_ONE_TO_ONE, column.getColumnName())
            .emitStatement("values.put(\"%s\", %s%s.%s(element.%s))", columnName, column.getType(),
                $$SUFFIX, GET_ID_FUNCTION, memberName);
      } else if (column.isDate()) {
        javaWriter.emitStatement("values.put(\"%s\", element.%s.getTime())", columnName,
            memberName);
      } else if (column.isOneToMany()) {
        childColumns.add(column);
      } else if (!column.isOneToManyChild()) {
        javaWriter.emitStatement("values.put(\"%s\", element.%s)", columnName, memberName);
      }
    }
    javaWriter.emitStatement("db.insert(\"%s\", null, values)", tableName);

    if (!childColumns.isEmpty()) {
      javaWriter.emitStatement("long id = DatabaseUtils.longForQuery(db, "
          + "\"SELECT ROWID FROM %s ORDER BY ROWID DESC LIMIT 1\", null)", tableName);
    }
    for (TableColumn childColumn : childColumns) {
      javaWriter.emitStatement("%s%s.%s(id, element.%s, db)", childColumn.getType(), $$SUFFIX,
          PARENT_INSERT_FUNCTION, childColumn.getMemberName());
    }

    javaWriter.endMethod();
  }
private void emitInsert(JavaWriter javaWriter) throws IOException {
    logger.d("emitInsert");
    String tableName = getTableName();
    javaWriter.beginMethod("void", $$INSERT_OBJECT_FUNCTION, EnumSet.of(PUBLIC, STATIC),
        getTargetClass(), "element", "SQLiteDatabase", "db")
        .emitStatement("ContentValues values = new ContentValues()");
    List<TableColumn> childColumns = Lists.newLinkedList();
    for (TableColumn column : columns) {
      String columnName = column.getColumnName();
      String memberName = column.getMemberName();
      if (column.isBlob() && !column.isByteArray()) {
        javaWriter.emitStatement("values.put(\"%s\", %s(element.%s))", columnName,
            SERIALIZE_FUNCTION, memberName);
      } else if (column.isOneToOne()) {
        javaWriter.emitStatement("%s%s.%s(element.%s, db)", column.getType(), $$SUFFIX,
            INSERT_ONE_TO_ONE, column.getColumnName())
            .emitStatement("values.put(\"%s\", %s%s.%s(element.%s))", columnName, column.getType(),
                $$SUFFIX, GET_ID_FUNCTION, memberName);
      } else if (column.isDate()) {
        javaWriter.emitStatement("values.put(\"%s\", element.%s.getTime())", columnName,
            memberName);
      } else if (column.isOneToMany()) {
        childColumns.add(column);
      } else if (!column.isOneToManyChild()) {
        javaWriter.emitStatement("values.put(\"%s\", element.%s)", columnName, memberName);
      }
    }
    javaWriter.emitStatement("db.insert(\"%s\", null, values)", tableName);

    if (!childColumns.isEmpty()) {
      javaWriter.emitStatement("long id = DatabaseUtils.longForQuery(db, "
          + "\"SELECT ROWID FROM %s ORDER BY ROWID DESC LIMIT 1\", null)", tableName);
    }
    for (TableColumn childColumn : childColumns) {
      javaWriter.emitStatement("%s%s.%s(id, element.%s, db)", childColumn.getType(), $$SUFFIX,
          PARENT_INSERT_FUNCTION, childColumn.getMemberName());
    }

    javaWriter.endMethod();
  }
Creates the function for inserting a new value into the database