Skip to content

Commit

Permalink
Fix generateMockRepos (closes #81)
Browse files Browse the repository at this point in the history
- add !selector combinator
  • Loading branch information
oyvindberg committed Jan 1, 2024
1 parent e5cce61 commit 187d3af
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 85 deletions.
3 changes: 3 additions & 0 deletions site-in/customization/customize-selected-relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ val mySchema = Selector.schemas("myschema") // picks all relations in schema

// heaviest syntax, but most flexible
val custom: Selector = relName => relName.schema.exists(_.contains("foo")) && relName.name.contains("bar")

// can also invert the selector
!Selector.schemas("myschema") // matches everything except schema "myschema"
```

Selectors are also composable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object GeneratedAdventureWorks {
},
enableDsl = true,
enableTestInserts = Selector.All,
generateMockRepos = !Selector.relationNames("purchaseorderdetail"),
readonlyRepo = Selector.relationNames("purchaseorderdetail")
)
val targetSources = buildDir.resolve(s"$projectPath/generated-and-checked-in")
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions typo/src/scala/typo/Selector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ trait Selector {
final def or(other: Selector): Selector = rel => include(rel) || other.include(rel)

final def and(other: Selector): Selector = rel => include(rel) && other.include(rel)

final def unary_! : Selector = rel => !include(rel)
}

object Selector {
Expand Down
12 changes: 7 additions & 5 deletions typo/src/scala/typo/internal/codegen/FilesTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ case class FilesTable(table: ComputedTable, options: InternalOptions, genOrderin
}

private val maybeMockRepo: Option[sc.File] =
for {
id <- table.maybeId
repoMethods <- table.repoMethods
dbLib <- options.dbLib
} yield relation.RepoMockFile(dbLib, id, repoMethods)
if (options.generateMockRepos.include(table.dbTable.name))
for {
id <- table.maybeId
repoMethods <- table.repoMethods
dbLib <- options.dbLib
} yield relation.RepoMockFile(dbLib, id, repoMethods)
else None

val all: List[sc.File] = List(
RowFile,
Expand Down

0 comments on commit 187d3af

Please sign in to comment.