sql

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const NullDatabaseId = DatabaseId(-1)

Variables

This section is empty.

Functions

func GetDatabaseRoles

func GetDatabaseRoles(ctx context.Context, db Database) map[DatabaseRoleId]DatabaseRole

func GetDatabases

func GetDatabases(ctx context.Context, conn Connection) map[DatabaseId]Database

func GetSchemas added in v0.4.0

func GetSchemas(ctx context.Context, db Database) map[SchemaId]Schema

func GetSqlLogins

func GetSqlLogins(ctx context.Context, conn Connection) map[LoginId]SqlLogin

func GetUsers

func GetUsers(ctx context.Context, db Database) map[UserId]User

func WithConnection

func WithConnection[T any](ctx context.Context, connectionFactory func(context.Context) *sql.DB, action func(*sql.DB) T) T

Types

type AADObjectId added in v0.2.0

type AADObjectId string

type Connection

type Connection interface {
	IsAzure(context.Context) bool
	GetPermissions(ctx context.Context, principalId GenericServerPrincipalId) ServerPermissions
	GrantPermission(ctx context.Context, principalId GenericServerPrincipalId, permission ServerPermission)
	RevokePermission(ctx context.Context, principalId GenericServerPrincipalId, permission string)
	// contains filtered or unexported methods
}

type ConnectionAuth

type ConnectionAuth interface {
	// contains filtered or unexported methods
}

type ConnectionAuthAzure

type ConnectionAuthAzure struct {
	ClientId     string
	ClientSecret string
	TenantId     string
}

type ConnectionAuthSql

type ConnectionAuthSql struct {
	Username string
	Password string
}

type ConnectionDetails

type ConnectionDetails struct {
	Host     string
	Database string
	Auth     ConnectionAuth
}

func (ConnectionDetails) Open

type Database

type Database interface {
	GetConnection(context.Context) Connection
	GetId(context.Context) DatabaseId
	Exists(context.Context) bool
	GetSettings(context.Context) DatabaseSettings
	Rename(_ context.Context, name string)
	SetCollation(_ context.Context, collation string)
	Drop(context.Context)
	Query(ctx context.Context, query string) []map[string]string
	Exec(ctx context.Context, script string)
	GetPermissions(ctx context.Context, id GenericDatabasePrincipalId) DatabasePermissions
	GrantPermission(ctx context.Context, id GenericDatabasePrincipalId, permission DatabasePermission)
	UpdatePermission(ctx context.Context, id GenericDatabasePrincipalId, permission DatabasePermission)
	RevokePermission(ctx context.Context, id GenericDatabasePrincipalId, permissionName string)
	// contains filtered or unexported methods
}

func CreateDatabase

func CreateDatabase(ctx context.Context, conn Connection, settings DatabaseSettings) Database

func GetDatabase

func GetDatabase(_ context.Context, conn Connection, id DatabaseId) Database

func GetDatabaseByName

func GetDatabaseByName(ctx context.Context, conn Connection, name string) Database

type DatabaseId

type DatabaseId int

type DatabasePermission added in v0.5.0

type DatabasePermission struct {
	Name            string
	WithGrantOption bool
}

type DatabasePermissions added in v0.5.0

type DatabasePermissions map[string]DatabasePermission

type DatabasePrincipalId

type DatabasePrincipalId interface {
	UserId | DatabaseRoleId | GenericDatabasePrincipalId
}

type DatabasePrincipalType

type DatabasePrincipalType int
const (
	UNONOWN DatabasePrincipalType = iota
	SQL_USER
	DATABASE_ROLE
	AZUREAD_USER
)

type DatabaseRole

func CreateDatabaseRole

func CreateDatabaseRole[T DatabasePrincipalId](ctx context.Context, db Database, name string, ownerId T) DatabaseRole

func GetDatabaseRole

func GetDatabaseRole(_ context.Context, db Database, id DatabaseRoleId) DatabaseRole

func GetDatabaseRoleByName

func GetDatabaseRoleByName(ctx context.Context, db Database, name string) DatabaseRole

type DatabaseRoleId

type DatabaseRoleId GenericDatabasePrincipalId

type DatabaseRoleMember

type DatabaseRoleMember struct {
	Id   GenericDatabasePrincipalId
	Name string
	Type DatabasePrincipalType
}

type DatabaseSettings

type DatabaseSettings struct {
	Name      string
	Collation string
}

type GenericDatabasePrincipalId

type GenericDatabasePrincipalId int
const EmptyDatabasePrincipalId GenericDatabasePrincipalId = -1

type GenericServerPrincipalId added in v0.6.0

type GenericServerPrincipalId int
const EmptyServerPrincipalId GenericServerPrincipalId = -1

type LoginId

type LoginId string
const NullLoginId LoginId = "<null>"

type NumericObjectId

type NumericObjectId interface {
	DatabaseId | DatabasePrincipalId | SchemaId | GenericServerPrincipalId
}

type ObjectId

type ObjectId interface {
	NumericObjectId | StringObjectId
}

type Schema added in v0.4.0

type Schema interface {
	GetDb(context.Context) Database
	GetId(context.Context) SchemaId
	GetName(context.Context) string
	GetOwnerId(context.Context) GenericDatabasePrincipalId
	ChangeOwner(_ context.Context, ownerId GenericDatabasePrincipalId)
	Drop(context.Context)
	GetPermissions(ctx context.Context, id GenericDatabasePrincipalId) SchemaPermissions
	GrantPermission(ctx context.Context, id GenericDatabasePrincipalId, permission SchemaPermission)
	UpdatePermission(ctx context.Context, id GenericDatabasePrincipalId, permission SchemaPermission)
	RevokePermission(ctx context.Context, id GenericDatabasePrincipalId, permission string)
}

func CreateSchema added in v0.4.0

func CreateSchema[T DatabasePrincipalId](ctx context.Context, db Database, name string, ownerId T) Schema

func GetSchema added in v0.4.0

func GetSchema(_ context.Context, db Database, id SchemaId) Schema

func GetSchemaByName added in v0.4.0

func GetSchemaByName(ctx context.Context, db Database, name string) Schema

type SchemaId added in v0.4.0

type SchemaId int

type SchemaPermission added in v0.5.0

type SchemaPermission struct {
	Name            string
	WithGrantOption bool
}

type SchemaPermissions added in v0.5.0

type SchemaPermissions map[string]SchemaPermission

type ServerPermission added in v0.6.0

type ServerPermission struct {
	Name            string
	WithGrantOption bool
}

type ServerPermissions added in v0.6.0

type ServerPermissions map[string]ServerPermission

type ServerPrincipalType added in v0.6.0

type ServerPrincipalType int
const (
	UNKNOWN ServerPrincipalType = iota
	SQL_LOGIN
	SERVER_ROLE
)

type ServerRole added in v0.6.0

type ServerRole interface {
	GetId(ctx context.Context) ServerRoleId
	GetSettings(ctx context.Context) ServerRoleSettings
	Rename(ctx context.Context, name string)
	Drop(ctx context.Context)
	HasMember(ctx context.Context, id GenericServerPrincipalId) bool
	AddMember(ctx context.Context, id GenericServerPrincipalId)
	RemoveMember(ctx context.Context, id GenericServerPrincipalId)
	GetMembers(ctx context.Context) ServerRoleMembers
}

func CreateServerRole added in v0.6.0

func CreateServerRole(ctx context.Context, conn Connection, settings ServerRoleSettings) ServerRole

func GetServerRole added in v0.6.0

func GetServerRole(_ context.Context, conn Connection, id ServerRoleId) ServerRole

func GetServerRoleByName added in v0.6.0

func GetServerRoleByName(ctx context.Context, conn Connection, name string) ServerRole

type ServerRoleId added in v0.6.0

type ServerRoleId GenericServerPrincipalId

type ServerRoleMember added in v0.6.0

type ServerRoleMember struct {
	Id   GenericServerPrincipalId
	Name string
	Type ServerPrincipalType
}

type ServerRoleMembers added in v0.6.0

type ServerRoleMembers map[GenericServerPrincipalId]ServerRoleMember

type ServerRoleSettings added in v0.6.0

type ServerRoleSettings struct {
	Name    string
	OwnerId GenericServerPrincipalId
}

type ServerRoles added in v0.6.0

type ServerRoles map[ServerRoleId]ServerRole

func GetServerRoles added in v0.6.0

func GetServerRoles(ctx context.Context, conn Connection) ServerRoles

type SqlLogin

type SqlLogin interface {
	GetId(context.Context) LoginId
	Exists(context.Context) bool
	GetSettings(context.Context) SqlLoginSettings
	UpdateSettings(ctx context.Context, settings SqlLoginSettings)
	Drop(ctx context.Context)
	// contains filtered or unexported methods
}

func CreateSqlLogin

func CreateSqlLogin(ctx context.Context, conn Connection, settings SqlLoginSettings) SqlLogin

func GetSqlLogin

func GetSqlLogin(_ context.Context, conn Connection, id LoginId) SqlLogin

func GetSqlLoginByName

func GetSqlLoginByName(ctx context.Context, conn Connection, name string) SqlLogin

type SqlLoginId added in v0.6.0

type SqlLoginId GenericServerPrincipalId

type SqlLoginSettings

type SqlLoginSettings struct {
	Name                    string
	Password                string
	MustChangePassword      bool
	DefaultDatabaseId       DatabaseId
	DefaultLanguage         string
	CheckPasswordExpiration bool
	CheckPasswordPolicy     bool
	PrincipalId             SqlLoginId
}

type StringObjectId

type StringObjectId interface {
	LoginId
}

type User

type User interface {
	GetId(context.Context) UserId
	GetDatabaseId(context.Context) DatabaseId
	GetSettings(context.Context) UserSettings
	Drop(context.Context)
	UpdateSettings(context.Context, UserSettings)
}

func CreateUser

func CreateUser(ctx context.Context, db Database, settings UserSettings) User

func GetUser

func GetUser(_ context.Context, db Database, id UserId) User

func GetUserByName

func GetUserByName(ctx context.Context, db Database, name string) User

type UserSettings

type UserSettings struct {
	Name        string
	LoginId     LoginId
	AADObjectId AADObjectId
	Type        UserType
}

type UserType added in v0.2.0

type UserType int
const (
	USER_TYPE_UKNOWN UserType = 0
	USER_TYPE_SQL    UserType = iota
	USER_TYPE_AZUREAD
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL