Documentation
¶
Index ¶
- type ArchiveRoleByNameParams
- type CreateRoleHierarchyEdgeParams
- type CreateRolePermissionParams
- type DBTX
- type DeleteRoleHierarchyParams
- type DeleteRolePermissionsParams
- type Dialect
- type GetRoleIDByNameParams
- type GetRoleIDByNameRow
- type ListPermissionsByNamesParams
- type ListPermissionsByNamesRow
- type ListRoleHierarchyRow
- type ListRolePermissionsRow
- type ListRolesByNamesParams
- type ListRolesByNamesRow
- type ListRolesRow
- type Querier
- type ResolvePermissionsForRolesParams
- type ResolvePermissionsForRolesRow
- type UpsertPermissionParams
- type UpsertRoleParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArchiveRoleByNameParams ¶
type ArchiveRoleByNameParams struct {
Name string
}
ArchiveRoleByNameParams are the arguments to ArchiveRoleByName.
type CreateRoleHierarchyEdgeParams ¶
CreateRoleHierarchyEdgeParams are the arguments to CreateRoleHierarchyEdge.
type CreateRolePermissionParams ¶
CreateRolePermissionParams are the arguments to CreateRolePermission.
type DBTX ¶
type DBTX interface {
ExecContext(context.Context, string, ...any) (sql.Result, error)
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...any) *sql.Row
}
DBTX is what a generated method needs from a database handle.
It is satisfied by *sql.DB, *sql.Tx, and *sql.Conn alike, and it is taken per call rather than held on the querier so that running a query inside a transaction is a different argument rather than a different querier.
type DeleteRoleHierarchyParams ¶
type DeleteRoleHierarchyParams struct {
ChildRoleID string
}
DeleteRoleHierarchyParams are the arguments to DeleteRoleHierarchy.
type DeleteRolePermissionsParams ¶
type DeleteRolePermissionsParams struct {
RoleID string
}
DeleteRolePermissionsParams are the arguments to DeleteRolePermissions.
type Dialect ¶
type Dialect string
Dialect names a SQL dialect this package was generated for.
It is a type rather than a string so that naming one that was not generated is a compile error rather than an error value at startup.
type GetRoleIDByNameParams ¶
type GetRoleIDByNameParams struct {
Name string
}
GetRoleIDByNameParams are the arguments to GetRoleIDByName.
type GetRoleIDByNameRow ¶
GetRoleIDByNameRow is one row of GetRoleIDByName's result.
type ListPermissionsByNamesParams ¶
type ListPermissionsByNamesParams struct {
Names []string
}
ListPermissionsByNamesParams are the arguments to ListPermissionsByNames.
type ListPermissionsByNamesRow ¶
type ListPermissionsByNamesRow struct {
ID string
Name string
Description string
ArchivedAt *time.Time
}
ListPermissionsByNamesRow is one row of ListPermissionsByNames's result.
type ListRoleHierarchyRow ¶
type ListRoleHierarchyRow struct {
ChildRoleID string
ParentID string
ParentName string
ParentDescription string
ParentCreatedAt time.Time
ParentLastUpdatedAt *time.Time
ParentArchivedAt *time.Time
}
ListRoleHierarchyRow is one row of ListRoleHierarchy's result.
type ListRolePermissionsRow ¶
type ListRolePermissionsRow struct {
RoleID string
PermissionID string
PermissionName string
PermissionDescription string
PermissionCreatedAt time.Time
PermissionLastUpdatedAt *time.Time
PermissionArchivedAt *time.Time
}
ListRolePermissionsRow is one row of ListRolePermissions's result.
type ListRolesByNamesParams ¶
type ListRolesByNamesParams struct {
Names []string
}
ListRolesByNamesParams are the arguments to ListRolesByNames.
type ListRolesByNamesRow ¶
ListRolesByNamesRow is one row of ListRolesByNames's result.
type ListRolesRow ¶
type ListRolesRow struct {
ID string
Name string
Description string
CreatedAt time.Time
LastUpdatedAt *time.Time
ArchivedAt *time.Time
}
ListRolesRow is one row of ListRoles's result.
type Querier ¶
type Querier interface {
// ArchiveRoleByName runs the :execrows query.
//
// The count means different things on different engines; see the note
// on Querier.
ArchiveRoleByName(ctx context.Context, db DBTX, arg ArchiveRoleByNameParams) (int64, error)
// CreateRoleHierarchyEdge runs the :exec query.
CreateRoleHierarchyEdge(ctx context.Context, db DBTX, arg CreateRoleHierarchyEdgeParams) error
// CreateRolePermission runs the :exec query.
CreateRolePermission(ctx context.Context, db DBTX, arg CreateRolePermissionParams) error
// DeleteRoleHierarchy runs the :execrows query.
//
// The count means different things on different engines; see the note
// on Querier.
DeleteRoleHierarchy(ctx context.Context, db DBTX, arg DeleteRoleHierarchyParams) (int64, error)
// DeleteRolePermissions runs the :execrows query.
//
// The count means different things on different engines; see the note
// on Querier.
DeleteRolePermissions(ctx context.Context, db DBTX, arg DeleteRolePermissionsParams) (int64, error)
// GetRoleIDByName runs the :one query.
GetRoleIDByName(ctx context.Context, db DBTX, arg GetRoleIDByNameParams) (GetRoleIDByNameRow, error)
// ListPermissionsByNames runs the :many query.
ListPermissionsByNames(ctx context.Context, db DBTX, arg ListPermissionsByNamesParams) ([]ListPermissionsByNamesRow, error)
// ListRoleHierarchy runs the :many query.
ListRoleHierarchy(ctx context.Context, db DBTX) ([]ListRoleHierarchyRow, error)
// ListRolePermissions runs the :many query.
ListRolePermissions(ctx context.Context, db DBTX) ([]ListRolePermissionsRow, error)
// ListRoles runs the :many query.
ListRoles(ctx context.Context, db DBTX) ([]ListRolesRow, error)
// ListRolesByNames runs the :many query.
ListRolesByNames(ctx context.Context, db DBTX, arg ListRolesByNamesParams) ([]ListRolesByNamesRow, error)
// ResolvePermissionsForRoles runs the :many query.
ResolvePermissionsForRoles(ctx context.Context, db DBTX, arg ResolvePermissionsForRolesParams) ([]ResolvePermissionsForRolesRow, error)
// UpsertPermission runs the :exec query.
UpsertPermission(ctx context.Context, db DBTX, arg UpsertPermissionParams) error
// UpsertRole runs the :exec query.
UpsertRole(ctx context.Context, db DBTX, arg UpsertRoleParams) error
}
Querier is every query in this package, with one signature per query regardless of which dialect answers it.
That is the point of this package: the params type, the row type, and the method signature are the same on every dialect, so nothing above this line knows or cares which database is underneath.
A note on the :execrows count ¶
MySQL reports rows *changed*: an UPDATE that sets a column to the value it already held affects zero rows there. Postgres and SQLite report rows *matched*, and count that same UPDATE as one.
So a statement that gates on the count — treating zero as "not found" — is correct on two engines and wrong on the third. Either give it a predicate that discriminates, or set clientFoundRows=true in the MySQL DSN, which switches MySQL to matched semantics.
A note on empty lists ¶
A list parameter that is empty matches nothing, on every dialect: Postgres binds an empty array to `= ANY`, and the other two expand to `IN (NULL)` because `IN ()` is a syntax error there. Asking for the rows whose key is in an empty set gets no rows back, which is what the empty set says, so a caller does not have to guard the call.
The negation is where they part company, and nothing below can warn you. An empty list makes `NOT IN (NULL)` never true, so it matches nothing, while Postgres's empty `<> ALL` is true and matches everything. Both readings are defensible and no shared signature can say which was meant — so test membership rather than its negation, and let the caller decide what an empty set means before it calls.
type ResolvePermissionsForRolesParams ¶
type ResolvePermissionsForRolesParams struct {
Names []string
}
ResolvePermissionsForRolesParams are the arguments to ResolvePermissionsForRoles.
type ResolvePermissionsForRolesRow ¶
type ResolvePermissionsForRolesRow struct {
Name string
}
ResolvePermissionsForRolesRow is one row of ResolvePermissionsForRoles's result.
type UpsertPermissionParams ¶
UpsertPermissionParams are the arguments to UpsertPermission.
type UpsertRoleParams ¶
UpsertRoleParams are the arguments to UpsertRole.