File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 56
56
END
57
57
RETURNING * ;
58
58
```
59
+
60
+ ## Nullable parameters
61
+
62
+ sqlc infers the nullability of any specified parameters, and often does exactly
63
+ what you want. If you want finer control over the nullability of your
64
+ parameters, you may use ` sql.narg() ` (** n** ullable arg) to override the default
65
+ behavior. Using ` sql.narg ` tells sqlc to ignore whatever nullability it has
66
+ inferred and generate a nullable parameter instead. There is no nullable
67
+ equivalent of the ` @ ` syntax.
68
+
69
+ Here is an example that uses a single query to allow updating an author's
70
+ name, bio or both.
71
+
72
+ ``` sql
73
+ -- name: UpdateAuthor :one
74
+ UPDATE author
75
+ SET
76
+ name = coalesce(sqlc .narg (' name' ), name),
77
+ bio = coalesce(sqlc .narg (' bio' ), bio)
78
+ WHERE id = sqlc .arg (' id' );
79
+ ```
80
+
81
+ The following code is generated:
82
+
83
+ ``` go
84
+ type UpdateAuthorParams struct {
85
+ Name sql.NullString
86
+ Bio sql.NullString
87
+ ID int64
88
+ }
89
+ ```
You can’t perform that action at this time.
0 commit comments