Skip to content

Commit dc7fe77

Browse files
committed
fixup null
1 parent 8da3601 commit dc7fe77

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

coderd/database/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/roles.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ WHERE
99
-- To do this manually in SQL, you can construct an array and cast it:
1010
-- cast(ARRAY[('customrole','ece79dac-926e-44ca-9790-2ff7c5eb6e0c')] AS name_organization_pair[])
1111
AND CASE WHEN array_length(@lookup_roles :: name_organization_pair[], 1) > 0 THEN
12-
(name, organization_id) = ANY (@lookup_roles::name_organization_pair[])
12+
-- Using 'coalesce' to avoid troubles with null literals being an empty string.
13+
(name, coalesce(organization_id, '00000000-0000-0000-0000-000000000000' ::uuid)) = ANY (@lookup_roles::name_organization_pair[])
1314
ELSE true
1415
END
1516
-- This allows fetching all roles, or just site wide roles

coderd/database/types.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,13 @@ func (*NameOrganizationPair) Scan(_ interface{}) error {
160160
// shell.
161161
//
162162
// SELECT ('customrole'::text,'ece79dac-926e-44ca-9790-2ff7c5eb6e0c'::uuid);
163-
// To see 'null' option
164-
// SELECT ('customrole',null);
163+
// To see 'null' option. Using the nil uuid as null to avoid empty string literals for null.
164+
// SELECT ('customrole',00000000-0000-0000-0000-000000000000);
165165
//
166166
// This value is usually used as an array, NameOrganizationPair[]. You can see
167167
// what that literal is as well, with proper quoting.
168168
//
169169
// SELECT ARRAY[('customrole'::text,'ece79dac-926e-44ca-9790-2ff7c5eb6e0c'::uuid)];
170170
func (a NameOrganizationPair) Value() (driver.Value, error) {
171-
if a.OrganizationID == uuid.Nil {
172-
return fmt.Sprintf(`('%s',)`, a.Name), nil
173-
}
174-
175171
return fmt.Sprintf(`(%s,%s)`, a.Name, a.OrganizationID.String()), nil
176172
}

0 commit comments

Comments
 (0)