3 date: 2019-06-16T18:53:54+02:00
14 Each SQL statement can have an optional front matter section written in YAML that is placed inside an SQL comment.
18 -- description: Retrieves a single user
19 -- repository: com.example.persistence.YourRepository
26 -- generateStandardApi: true
27 -- generateBatchApi: false
28 -- generateStreamEagerApi: false
29 -- generateStreamLazyApi: false
30 -- generateRxJavaApi: false
31 -- catchAndRethrow: true
37 While parsing your `.sql` files, `YoSQL` will strip the SQL comment prefix (`--`) and read the remaining text as a YAML object. Its available fields are explained below.
41 The `name` field can be used to change the name of an SQL statement. Typically, the name is auto-detected from the `.sql` file name, however if you want to place multiple SQL statements in one file, use `name` to give each statement a unique name instead of relying on the auto-numbering `YoSQL` is using by default.
52 The `description` field can be used to add a description to your SQL statements that will be part of generated Javadocs.
55 -- description: Retrieves a single user
63 The `repository` field can be used to change which repository will contain the SQL statement. By default, `YoSQL` will auto-detect the repository based on the location of the `.sql` file. In case you want to structure your `.sql` files in a specific way, but move some SQL statements to specific repositories, use `repository` together with the fully-qualified name of the target repository.
66 -- repository: com.example.persistence.YourRepository
72 The `repository` field takes the [basePackageName](../../configuration/repositories/basepackagename/) into account, e.g. you could shorten the above example to just `YourRepository` if your base package is `com.example.persistence`. If your repository starts with the base package already, it won't be added twice. Likewise, it is possible to add any number of subpackages in front of your repository, e.g. `your.own.domain.YourRepository`.
76 The `vendor` field can be used to assign a SQL statement to a specific database vendor. Use `vendor` in case you are writing SQL statements that are different for each database. We recommend, to provide a vendor-less statement as a fallback, in order to support as many databases as possible.
85 -- vendor: Microsoft SQL Server
97 With the above configuration in place, the first statement will be executed when running against a H2 database, the second one when using Microsoft SQL Server and the last one for every other database.
101 The `parameters` field can be used to change the type of input parameters. We recommend to use `parameters` on all statements that expect user inputs to improve the type-safety of your code.
112 The above configuration will generate code that use the primitive `int` type instead of `java.lang.Object` for the parameter `userId` in generated code.
116 The `type` field can be used to change the type of your SQL statement. By default, `YoSQL` will [auto-detect the type based on the name](../sql-files/) of your SQL statement. Possibles types are `READING`, `WRITING`, `CALLING`.
127 The `returningMode` field can be used to change what the generated methods are returning. By default, `LIST` is used which can contain zero-to-many entities. Use `FIRST` in order to get just the first result (zero-to-one) or `ONE` to get the one result, while failing if there are more than one.
130 -- returningMode: ONE
136 ## generateStandardApi
138 The `generateStandardApi` field can be used to overwrite the globally configured `generateStandardApi` option. Use `generateStandardApi` in case you want to enable/disable generating *standard* methods.
141 -- generateStandardApi: true
149 The `generateBatchApi` field can be used to overwrite the globally configured `generateBatchApi` option. Use `generateBatchApi` in case you want to enable/disable generating batch methods.
152 -- generateBatchApi: false
158 ## generateStreamEagerApi
160 The `generateStreamEagerApi` field can be used to overwrite the globally configured `generateStreamEagerApi` option. Use `generateStreamEagerApi` in case you want to enable/disable generating eager stream methods.
163 -- generateStreamEagerApi: false
169 ## generateStreamLazyApi
171 The `generateStreamLazyApi` field can be used to overwrite the globally configured `generateStreamLazyApi` option. Use `generateStreamLazyApi` in case you want to enable/disable generating lazy stream methods.
174 -- generateStreamLazyApi: false
182 The `generateRxJavaApi` field can be used to overwrite the globally configured `generateRxJavaApi` option. Use `generateRxJavaApi` in case you want to enable/disable generating rxjava2 based methods.
185 -- generateRxJavaApi: false
193 The `catchAndRethrow` field can be used to overwrite the globally configured `catchAndRethrow` option. Use `catchAndRethrow` in case you want to enable/disable catching checked exceptions and rethrowing them as runtime exceptions.
196 -- catchAndRethrow: true