database

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package database provides Runa database primitives.

Index

Constants

View Source
const DefaultName = "default"

Variables

This section is empty.

Functions

func Provider

func Provider(options ...ProviderOption) runaprovider.Provider

Types

type Config

type Config struct {
	Name string
	App  any
}

Config is passed to database drivers.

type Database

type Database interface {
	Name() string
	Kind() string
	Raw() any
	Ping(ctx context.Context) error
	Close(ctx context.Context) error
	Info() Info
}

Database is a named data source runtime.

type Driver

type Driver interface {
	Open(ctx context.Context, config Config) (Database, error)
}

Driver opens a named database runtime.

type Info

type Info struct {
	Name    string
	Kind    string
	Dialect string
	Status  string
	Meta    core.Map
}

Info stores database runtime health metadata.

type ProviderOption

type ProviderOption func(*provider)

func RegisterDriver

func RegisterDriver(name string, driver Driver) ProviderOption

RegisterDriver registers a database driver with the provider.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry stores named database drivers and runtimes.

func Default

func Default() *Registry

Default returns the default app database registry.

func New

func New() *Registry

New creates a registry.

func (*Registry) Close

func (registry *Registry) Close(ctx context.Context) error

Close closes all open database runtimes.

func (*Registry) Get

func (registry *Registry) Get(name string) Database

Get returns a named database runtime.

func (*Registry) Info

func (registry *Registry) Info() []Info

Info returns database runtime snapshots.

func (*Registry) MustGet

func (registry *Registry) MustGet(name string) Database

MustGet returns a named database runtime or panics.

func (*Registry) Open

func (registry *Registry) Open(ctx context.Context, app any) error

Open opens all registered databases.

func (*Registry) Ping

func (registry *Registry) Ping(ctx context.Context, name string) error

Ping pings a named database runtime.

func (*Registry) RegisterDriver

func (registry *Registry) RegisterDriver(name string, driver Driver)

Register registers or replaces a named driver.

func (*Registry) Shutdown

func (registry *Registry) Shutdown(ctx context.Context) error

Shutdown closes open database runtimes when managed by DI.

type SQLLog

type SQLLog struct {
	Time      time.Time
	Database  string
	Dialect   string
	Operation string
	Model     string
	Table     string
	SQL       string
	Rows      int64
	Latency   time.Duration
	Slow      bool
	Error     string
}

SQLLog describes one SQL execution event emitted by database drivers.

type SQLRecorder

type SQLRecorder interface {
	RecordSQL(SQLLog)
}

SQLRecorder consumes SQL execution events.

Directories

Path Synopsis
oro module
redis module

Jump to

Keyboard shortcuts

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