Skip to content

Commit

Permalink
Merge pull request #333 from gfx/delete_all
Browse files Browse the repository at this point in the history
add OrmaDatabase#deleteAll()
  • Loading branch information
gfx authored Nov 11, 2016
2 parents 741809e + 4936cfe commit 29beea3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public Completable transactionNonExclusiveAsync(@NonNull Runnable task) {
return connection.transactionNonExclusiveAsync(task);
}

public void deleteAll() {
connection.deleteAll();
}

/**
* Retrieves a model from a cursor. */
@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testNumberOfSchemas() throws Exception {
}

@Test
public void testResetDatabase() throws Exception {
public void testDeleteAll() throws Exception {
OrmaDatabase db = OrmaDatabase.builder(getContext())
.name(NAME)
.trace(true)
Expand All @@ -91,12 +91,7 @@ public Author call() {

assertThat(db.selectFromAuthor().count(), is(1));

getContext().deleteDatabase(NAME);
db = OrmaDatabase.builder(getContext())
.name(NAME)
.trace(true)
.tryParsingSql(false)
.build();
db.deleteAll();

assertThat(db.selectFromAuthor().count(), is(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ public List<MethodSpec> buildMethodSpecs(ClassName builderClass) {
.build()
);

methodSpecs.add(
MethodSpec.methodBuilder("deleteAll")
.addModifiers(Modifier.PUBLIC)
.addStatement("$L.deleteAll()", connection)
.build()
);

database.getSchemas().forEach(schema -> {
String simpleModelName = schema.getModelClassName().simpleName();
CodeBlock schemaInstance = schema.createSchemaInstanceExpr();
Expand Down

0 comments on commit 29beea3

Please sign in to comment.