sql

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 12 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 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
	// 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)
	// 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 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 LoginId

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

type NumericObjectId

type NumericObjectId interface {
	DatabaseId | DatabasePrincipalId
}

type ObjectId

type ObjectId interface {
	NumericObjectId | StringObjectId
}

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 SqlLoginSettings

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

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