saas

package
v0.0.0-...-02df951 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 11 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConnStrResolver data.ConnStrResolver
View Source
var DbProvider sgorm.DbProvider
View Source
var EnsureDbExist = func(s string) error {
	dbname, err := utils.ParseDBNameFromPostgresDSN(s)
	if err != nil {
		return err
	}

	noDbDsn, err := utils.RemoveDBNameFromPostgresDSN(s)
	if err != nil {
		return err
	}

	db, err := sql.Open("pgx", noDbDsn)
	if err != nil {
		return err
	}

	var exists bool
	err = db.QueryRowContext(context.Background(), "SELECT EXISTS(SELECT 1 FROM pg_database WHERE datname = $1)", dbname).Scan(&exists)
	if err != nil {
		return err
	}

	if !exists {
		_, err := db.ExecContext(context.Background(), fmt.Sprintf("CREATE DATABASE \"%s\"", dbname))
		if err != nil {
			return err
		}
	}

	return db.Close()
}

Functions

func InitCache

func InitCache()

func InitConnStrGenerator

func InitConnStrGenerator(sharedDsn string)

func InitConnStrResolver

func InitConnStrResolver(sharedDsn string)

func InitDbProvider

func InitDbProvider()

func InitSaas

func InitSaas(sharedDsn string)

func NewClientProvider

func NewClientProvider() saas.ClientProvider[*gorm.DB]

Types

type TenantStore

type TenantStore struct {
	DbProvider sgorm.DbProvider
}
var TenantStorage *TenantStore

func (*TenantStore) GetByNameOrId

func (t *TenantStore) GetByNameOrId(ctx context.Context, nameOrId string) (*saas.TenantConfig, error)

Jump to

Keyboard shortcuts

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