-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfacil_reference.yaml
532 lines (440 loc) · 24.3 KB
/
facil_reference.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# This document explains everything you can specify in facil.yaml. You can of course often
# get away with a much simpler config file. Click the link below to view the minimal
# config file that is added to your project if you build without an existing config file:
# https://github.com/cmeeren/Facil/blob/master/src/Facil.Generator/facil_minimal.yaml
# The optional 'configs' section allows you to specify where variables are resolved from.
# Each array item translates more or less exactly into a call to the corresponding
# Microsoft.Extensions.Configuration.ConfigurationBuilder.Add* method, in the order you
# specify here (i.e., later config sources will override already added config sources if
# there are collisions). Any config type may be added multiple times. This section is only
# required if you are using variables (e.g. for the connection string). For more
# information, see:
# - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration
# - https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.configurationbuilder
configs:
# 'appSettings' allow you to use configuration values from appsettings.json.
- appSettings: path/from/project/to/appsettings.json
# 'userSecrets' allow you to use configuration values from user secrets.
- userSecrets: 80d5e7ec-f577-4360-b60a-f10ea004da1d
# 'envVars' allow you to use configuration values from environment variables. Supply the
# prefix that environment variable names must start with. The prefix will be removed
# from the environment variable names.
- envVars: ''
# Rulesets allow you to specify what you should generate. Each ruleset may only use a
# single DB and generates a single file. You will often only need one ruleset.
rulesets:
# 'connectionString' is the only required property of a ruleset. You may use a
# variable here with the syntax $(VariableName).
- connectionString: $(ConnectionStrings:Db)
# The filename and namespace/module declaration of the generated file. The values
# below are the defaults.
filename: DbGen.fs
namespaceOrModuleDeclaration: module DbGen
# The base path for all scripts (including temp table definitions) in this ruleset,
# relative to the project directory.
scriptBasePath: ../some/path
# 'prelude' contains anything you want to insert at the top of the generated file.
# This can for example be preprocessor directives to disable compiler warnings.
# (#nowarn "49" is always inserted by Facil and is just shown as an example.) You
# don't have to think about the initial indentation; all lines will be deindented so
# that the least indented line is not intended in the generated file.
prelude: |
#nowarn "49"
# Rules to specify which stored procedures are included in the generation and how they
# are generated. Each rule requires either 'include' or 'for'. All other properties
# are optional. The effective config of any stored procedure is taken from all
# matching rules, with values from later rules overriding values from earlier rules.
procedures:
# 'include' contains a regex to be matched against the schema-qualified procedure
# name (e.g. dbo.MyProcedure). All procedures that match the 'include' pattern for
# any rule will be included in generation, unless they are also matched by a
# corresponding 'except' pattern.
#
# The rule below specifies that all procedures should be included in generation,
# except the procedure 'dbo.ProcToExclude', and that all the matched procedures
# should use ValueOption instead of Option for nullable output columns (unless
# overridden by later rules).
#
# Note that all regex patterns in the YAML file are case sensitive by default.
# Prefix them with '(?i)' to make them case insensitive (e.g. '(?i)^dbo\.myProc$').
- include: .*
except: '^dbo\.ProcToExclude$'
voptionOut: true
# 'for' contains a regex that specifies which already included procedures (also from
# 'include' in later rules) this rule applies to. It will not cause additional
# procedures to be included.
#
# The rule below applies to all procedures containing 'dbo.User_' except those
# containing 'dbo.User_Id'.
- for: 'dbo\.User_'
except: 'dbo\.User_Id'
# 'result' specifies the type of the returned rows. Valid values:
# - 'auto' (default): If a single matching table DTO (see later) is found, use
# that. Otherwise, use anonyomus records. Will warn and fall back to anonyomus
# records if there are multiple matching table DTOs. Will not match
# voption-enabled table DTOs if voptionOut if false, and vice versa.
# - 'anonymous': Use anonymous records.
# - 'nominal': Generate and use a normal record type (a unique type is defined
# for each procedure).
# - A qualified table name, e.g. 'dbo.User': If the name matches an included
# table DTO (see later), use that. Otherwise, treat as a custom record type as
# described in the next point.
# - A (sufficiently qualified) user record type, e.g. 'MyModule.MyDto'. This must
# be a record whose record constructor is accessible by the generated code.
result: dbo.User
# 'paramDto' specifies the parameter type of the WithParameters overload that
# accepts a generic DTO type. Valid values:
# - 'inline' (default): Uses SRTP to accept any type that has the correct
# members.
# - 'nominal': Generate and use a normal record type (a unique type is defined
# for each procedure).
# - 'skip': Skips the overload. If you have many procedures and generally don't
# use these overloads, removing them may improve IDE performance and
# compilation times. Default false.
paramDto: nominal
# Deprecated; use 'paramDto: skip' instead.
#
# If true, will skip the 'WithParameters' overload that acceps a generic DTO type.
# If you have many procedures and generally don't use these overloads, removing
# them may improve IDE performance and compilation times. Default false.
skipParamDto: true
# Whether to use ValueOption instead of Option for nullable parameters. Default
# false.
voptionIn: true
# Whether to use ValueOption instead of Option for nullable columns in returned
# records. Note that if the result is a table DTO, that table DTO must have a
# matching 'voption' configuration. Defalt false.
voptionOut: true
# If true and the result set consists of a single named column, return a record
# with a single field (e.g. {| col: int |}). If false, returns the scalar value
# directly (just 'int' in this example). Default false.
recordIfSingleCol: true
# If true, the return value of the procedure will be made available (except when
# using lazy execution).
useReturnValue: true
# 'params' allows you to specify settings for individual parameters.
params:
# The keys are the names of the parameters without '@'. The special value ''
# (empty string) specifies base rules inherited by all parameters in this rule.
'': { }
someParam:
# Whether the parameter is nullable. Parameters are nullable by default if
# they are defined with default value NULL in the procedure. You can override
# it using this property.
nullable: true
# The property name for this parameter if passing parameters using a DTO
# object. By default, it's equal to the actual parameter name with the first
# letter upper-cased.
dtoName: SOMEparam
# The value this parameter will have during build when inferring the output
# result set. This is probably only needed if you use dynamic SQL and this
# parameter represents e.g. a column name. Only string parameters (e.g.
# NVARCHAR) are supported.
buildValue: foo
# If a procedure uses temp tables that must be loaded by Facil (effectively acting as
# parameters for the procedure), place the definitions here. Note that while this
# property can be overridden by later matching procedure rules, it is not merged (or
# removed); the last specified tempTables array for any given procedure will be used.
#
# Note that the temp table definitions will be executed during build, so don't do
# anything dangerous here.
tempTables:
# You can supply the definition directly as a string.
- definition: |
CREATE TABLE #myTempTable(
Col1 INT NOT NULL PRIMARY KEY,
Col2 NVARCHAR(100) NULL
)
# If using a single line, remember to enclose in quotes (otherwise everything
# after # will be a YAML comment and not be part of the definition)
- definition: 'CREATE TABLE #myTempTable(Col1 INT NOT NULL)'
# You can also specify a path to a SQL file containing the definition. The
# path is relative to scriptBasePath (by default the project directory).
- definition: path/to/my/tempTableDefinition.sql
# 'columns' allows you to specify settings for individual output columns.
columns:
# The keys are the column names. The special value '' (empty string) specifies
# base rules inherited by all columns in this rule.
'':
# Whether the column should be ignored. Can be used e.g. to remove columns
# with unsupported data types.
skip: true
SomeColumn:
skip: false
# Override Facil's inferred nullability.
nullable: false
# Rules for which SQL script files are included. These work just like stored procedure
# rules, except that 'include', 'for', and 'except' are glob patterns, not regex
# patterns. For supported patterns, see the glob implementation Facil uses:
# https://github.com/kthompson/glob
#
# The SQL files must exist under scriptBasePath (by default the project directory);
# you may not use .. to go out of this directory.
#
# The SQL files do not need to be included in the build output; the script contents
# will be inlined in the generated code.)
scripts:
- include: '**/*.sql'
except: SQL/ScriptToExclude.sql
# The following work exactly like they do in stored procedure rules.
result: anonymous
paramDto: nominal
skipParamDto: true
voptionIn: true
voptionOut: true
recordIfSingleCol: true
tempTables: ...
- for: SQL/MyScript.sql
# 'params' allows you to specify settings for individual script parameters.
#
# Type inference in scripts is limited due to limitations in SQL Server's
# sp_describe_undeclared_parameters, which Facil uses to get parameter information
# for sripts. Notably, the following does not work out of the box:
# - Parameters used multiple times will give errors
# - Table-valued parameters will give errors
# - Nullability is not inferred (by default, Facil assumes all script parameters
# are non-nullable)
#
# To work around this, script rules also supports a 'params' property that allows
# you to specify, for each problematic parameter (you don't have to specify the
# ones that work), which SQL type it is and whether it is nullable.
params:
# The keys are the names of the parameters without '@'. The special value ''
# (empty string) specifies base rules inherited by all parameters in this rule.
'':
# Whether the parameter is nullable. Default false.
nullable: true
someParam:
# The type of parameter. This is required if the parameter is used more than
# once in the script or if it is a table-valued parameter (see below).
type: NVARCHAR(50)
# The property name for this parameter if passing parameters using a DTO
# object. By default, it's equal to the actual parameter name with the first
# letter upper-cased.
dtoName: SOMEparam
# The value this parameter will have during build when inferring the output
# result set. This is probably only needed if you use dynamic SQL and this
# parameter represents e.g. a column name. Only string parameters (e.g.
# NVARCHAR) are supported.
buildValue: foo
anotherParam:
# For table-valued parameters, specify the schema-qualified name of a
# user-defined table type. Note that table-valued parameters can not be
# nullable.
type: dbo.MultiColNull
# 'columns' allows you to specify settings for individual output columns.
columns:
# The keys are the column names. The special value '' (empty string) specifies
# base rules inherited by all columns in this rule.
'':
# Whether the column should be ignored. Can be used e.g. to remove columns
# with unsupported data types.
skip: true
SomeColumn:
skip: false
# Override Facil's inferred nullability.
nullable: false
# Facil can generate simple boilerplate per-table CRUD scripts.
#
# These scripts are not stored on disk, but work just like you had written them
# yourself and placed them in scriptBasePath. You can therefore further configure them
# using script rules as demonstrated above, except for parameter config, which will be
# ignored (Facil has enough information to know the type and nullability of all
# parameters for table scripts).
tableScripts:
- include: '.*'
except: 'dbo\.SomeTable'
# The scripts to create. For rules where include/for matches more than one table,
# rules for scripts with the same type and (final) name will be merged, with
# values for later rules taking precedence (columns will be merged). It is
# possible to have more than one rule of the same type for any given table.
scripts:
# Generates a script to insert a row.
- type: insert
# The name of the script. The values '{SchemaName}' and '{TableName}' will be
# replaced with the schema and table name, respectively. The default is
# '{TableName}_Insert'. You can use path separators to 'place' the script in a
# subdirectory.
name: 'subdir/{SchemaName}_{TableName}_Insert'
# 'columns' allows you to specify settings for individual output columns.
columns:
# Rules inherited by all columns.
'': { }
MyIdentityColumn:
# Don't insert this column. Default true for identity columns, false for
# normal columns.
skip: true
# Output this column. You can output as many columns as you want.
output: true
Column With Spaces:
# The name of the script parameter.
paramName: columnWithSpaces
# Generates a script to insert a batch of rows efficiently.
#
# The script is the same as if you had witten a manual insert script using a temp table to load the rows. In
# other words, Facil uses SqlBulkCopy to load the rows, and you can configure the created SqlBulkCopy using
# ConfigureBulkCopy.
#
# Supports the same rules as 'insert'. The default name is '{TableName}_InsertBatch'.
- type: insertBatch
# Generates a script to update a row by its primary key.
#
# Supports the same rules as 'insert'. The default name is
# '{TableName}_Update'. Skipping a column means it's not updated. (Identity
# columns are not skipped by default, but this fact is likely irrelevant for
# most updates).
- type: update
# Generates a script to update a batch of rows efficiently.
#
# The script is the same as if you had witten a manual update script using a temp table to load the rows. In
# other words, Facil uses SqlBulkCopy to load the rows, and you can configure the created SqlBulkCopy using
# ConfigureBulkCopy.
#
# Supports the same rules as 'update'. The default name is '{TableName}_UpdateBatch'.
- type: updateBatch
# Generates a script that uses MERGE to insert a row or update a row by its
# primary key.
#
# Supports the same rules as 'insert'. The default name is
# '{TableName}_Merge'. Skipping a column means it's not inserted/updated.
- type: merge
# Add WITH (HOLDLOCK) to the merge statement
holdlock: true
# Generates a script to merge a batch of rows efficiently.
#
# The script is the same as if you had witten a manual merge script using a temp table to load the rows. In
# other words, Facil uses SqlBulkCopy to load the rows, and you can configure the created SqlBulkCopy using
# ConfigureBulkCopy.
#
# Supports the same rules as 'merge'. The default name is '{TableName}_MergeBatch'.
- type: mergeBatch
# Generates a script to delete a row by its primary key.
#
# Supports the same rules as 'insert'. The default name is
# '{TableName}_Delete'. Column skip rules are irrelevant and ignored.
- type: delete
# Generates a script to delete a batch of row efficiently.
#
# Supports the same rules as 'insert'. The default name is
# '{TableName}_DeleteBatch'. Column skip rules are irrelevant and ignored.
- type: deleteBatch
# Generates a script to get all rows from a table.
#
# Supports the same rules as 'insert'. The default name is '{TableName}_All'.
# Skipping a column means it's not in the SELECT list. The 'output' and
# 'paramName' column rules are ignored.
- type: getAll
# Generates a script to get a row by its primary key.
#
# Supports the same rules as 'insert'. The default name is '{TableName}_ById'.
# Skipping a column means it's not in the SELECT list. The 'output' and
# 'paramName' column rules are ignored.
- type: getById
# 'selectColumns' is a short way of specifying which columns to include. The value shown here is is simply
# syntactic sugar for the 'columns' configuration shown below. If you specify both, any 'skip' values under
# 'columns' take precedence over what's specified in 'includeColumns'.
selectColumns:
- Col1
- Col2
# 'columns' allows you to specify settings for individual columns.
columns:
'':
skip: true
Col1:
skip: false
Col2:
skip: false
# Generates a script to get rows by a batch of primary keys using a
# table-valued parameter.
#
# Supports the same rules as 'getById'. The default name is
# '{TableName}_ByIds'.
- type: getByIdBatch
# Facil can use a table type in this script if:
# - For single-column types/PKs: The table type column data type matches the
# PK column data type.
# - For multi-column types/PKs: The table type columns' name and data types
# match those of the primary key columns (the column order is ignored).
#
# If there are more than one matching table type, you must specify the fully
# qualified name of the table type to use.
tableType: dbo.MyTableType
# Generates a script to get a row by a set of column values.
#
# Supports the same rules as 'getById'. The default name is
# '{TableName}_By{ColumnNames}' where '{ColumnNames}' is e.g. 'Col1' or
# 'Col1AndCol2'
- type: getByColumns
# The columns to select by. Mandatory.
filterColumns:
- Col1
- Col2
# Generates a script to get rows by a batch of column values.
#
# Supports the same rules as 'getByIdBatch' and 'getByColumns'. The default
# name is '{TableName}_By{ColumnNames}s' where '{ColumnNames}' is e.g. 'Col1'
# or 'Col1AndCol2'
- type: getByColumnsBatch
# Works like in getByIdBatch scripts.
tableType: dbo.MyTableType
# Works like in getByColumns scripts.
filterColumns:
- Col1
- Col2
# Facil can generate DTO record types for tables. These can then (automatically or
# manually) be used as the return types of procedures and scripts. This can make it
# easier for you to map between the DTO and your domain types, because you can just
# write functions that convert to/from this table DTO, instead of having to write a
# type annotation with all the fields of the corresponding anonymous record (or use
# SRTPs).
tableDtos:
# 'include', 'for', and 'except' work just like in stored procedure rules, and are
# matched against the schema-qualified table name.
- include: '.*'
except: 'dbo\.SomeTable'
# Whether to use ValueOption instead of Option for nullable columns. Default
# false.
voption: true
# Adds a constructor that accepts an object whose properties are a superset of the properties of the table DTO.
# This can be useful if you want to use the table DTO with a script that returns additional columns (for example
# representing the total number of rows, or an additional value to group by).
mappingCtor: true
# 'includeColumns' is a short way of specifying which columns to include. The value shown here is is simply
# syntactic sugar for the 'columns' configuration shown below. If you specify both, any 'skip' values under
# 'columns' take precedence over what's specified in 'includeColumns'.
includeColumns:
- SomeColumn
# 'columns' allows you to specify settings for individual columns.
columns:
# The keys are the column names. The special value '' (empty string) specifies
# base rules inherited by all columns in this rule.
'':
# Whether the column should be ignored. Can be used e.g. to remove columns
# with unsupported data types.
skip: true
SomeColumn:
skip: false
# Override Facil's inferred nullability.
nullable: false
# Facil automatically generates table type constructors for table types used as a
# parameter in any included stored procedure or script.
tableTypes:
# 'for' and 'except' work just like in stored procedure rules, and are matched
# against the schema-qualified table type name. Note that 'include' is not
# supported; Facil always generates wrappers for the table types used in included
# procedure and script parameters.
- for: '.*'
except: 'dbo\.SomeTableType'
# Whether to use ValueOption instead of Option for nullable columns. Default
# false.
voption: true
# If true, will skip the 'create' overload that acceps a generic DTO type. If you
# have many table types and generally don't use these overloads, removing them may
# improve IDE performance and compilation times. Default false.
skipParamDto: true
# Here we start another array item in the top-level 'rulesets' array, to generate another file
# with a different configuration.
- connectionString: $(ConnectionStrings:AnotherDb)
filename: DbGen2.fs
namespaceOrModuleDeclaration: module DbGen2
# etc.