Documentation
¶
Index ¶
- Variables
- func Register(rt *runner.Runtime)
- func RegisterDatabaseMigrate(rt *runner.Runtime)
- func RegisterDefer(rt *runner.Runtime)
- func RegisterSession(rt *runner.Runtime)
- func RegisterSharedMemory(rt *runner.Runtime)
- func RegisterShutdown(rt *runner.Runtime)
- func SharedMemoryContext(ctx context.Context, s *SharedMemory) context.Context
- type Database
- func (b *Database) Begin(ctx context.Context) (any, error)
- func (b *Database) Close(ctx context.Context) (any, error)
- func (b *Database) Commit(ctx context.Context) (any, error)
- func (b *Database) Connect(ctx context.Context) (any, error)
- func (b *Database) Get(ctx context.Context, query string, args ...any) (any, error)
- func (b *Database) GetAll(ctx context.Context, query string, args ...any) (any, error)
- func (b *Database) Insert(ctx context.Context, table string, value any) (any, error)
- func (b *Database) InsertID(ctx context.Context) (any, error)
- func (b *Database) Query(ctx context.Context, query string, args ...any) (any, error)
- func (b *Database) Replace(ctx context.Context, table string, value any) (any, error)
- func (b *Database) Rollback(ctx context.Context) (any, error)
- func (b *Database) RowsAffected(ctx context.Context) (any, error)
- func (b *Database) SetID(id string)
- func (b *Database) Update(ctx context.Context, table string, value any, keyColumns ...any) (any, error)
- type DatabaseMigrate
- type SessionManager
- type SessionStorage
- type SessionStorageDisk
- func (s *SessionStorageDisk) Delete(ctx context.Context, id string) error
- func (s *SessionStorageDisk) Load(ctx context.Context, id string) ([]byte, error)
- func (s *SessionStorageDisk) Prune(ctx context.Context, maxAge time.Duration) error
- func (s *SessionStorageDisk) Save(ctx context.Context, id string, data []byte) error
- type SessionStorageMemory
- func (s *SessionStorageMemory) Delete(ctx context.Context, id string) error
- func (s *SessionStorageMemory) Load(ctx context.Context, id string) ([]byte, error)
- func (s *SessionStorageMemory) Prune(ctx context.Context, maxAge time.Duration) error
- func (s *SessionStorageMemory) Save(ctx context.Context, id string, data []byte) error
- type SharedMemory
- func (s *SharedMemory) Clear(_ context.Context)
- func (s *SharedMemory) Count(_ context.Context, key string) string
- func (s *SharedMemory) Delete(_ context.Context, key string) bool
- func (s *SharedMemory) Get(_ context.Context, key string) string
- func (s *SharedMemory) Has(_ context.Context, key string) bool
- func (s *SharedMemory) Incr(_ context.Context, key string) int64
- func (s *SharedMemory) Set(_ context.Context, key, value string)
Constants ¶
This section is empty.
Variables ¶
var ErrReadOnly = errors.New("database is read-only")
ErrReadOnly is what a refusal by a read-only client matches with errors.Is. The runtime surfaces the refusal to PHP as a thrown exception, so a script catches it like any other database error.
Functions ¶
func RegisterDatabaseMigrate ¶ added in v0.2.3
RegisterDatabaseMigrate installs the Database\Migrate binding.
func RegisterDefer ¶ added in v0.1.3
RegisterDefer installs defer() in the global function namespace.
func RegisterSession ¶ added in v0.2.2
RegisterSession installs session storage and manager bindings.
func RegisterSharedMemory ¶ added in v0.2.1
RegisterSharedMemory installs SharedMemory in the runtime.
func RegisterShutdown ¶ added in v0.2.1
RegisterShutdown installs register_shutdown_function() in the global function namespace. Callbacks run in registration order when Runtime.Run finishes, including after exit or an execution error.
func SharedMemoryContext ¶ added in v0.2.1
func SharedMemoryContext(ctx context.Context, s *SharedMemory) context.Context
SharedMemoryContext binds an SharedMemory instance into the context.
Types ¶
type Database ¶
type Database struct {
Bridge *client.Bridge
ID string
// IsReadonly restricts the client to statements that only read. It is a
// property of the client, not of the connection: PHP reads and writes it as
// `$db->is_readonly`, and it lives as long as the client does, which for a
// served request is the request.
//
// It refuses insert(), replace() and update() outright, and refuses any
// statement passed to query(), get() or get_all() that does not start with
// a read-only keyword (see readOnlyStatements). Transactions, connection
// pinning and the result accessors stay available, since a read-only
// transaction is a read.
//
// The restriction is a boundary for the code holding this client, not a
// sandbox around the script: the script that set it can unset it. A
// connection that must not write belongs to a database user without the
// grant to, and this marks the code that must not write.
IsReadonly bool
// contains filtered or unexported fields
}
Database adds request tracing to the database binding.
func (*Database) Begin ¶ added in v0.2.2
Begin starts a transaction and opens the span measuring it. The span stays open until Commit or Rollback, so a transaction is one region in the trace rather than an open marker and a close marker to pair up.
func (*Database) Get ¶ added in v0.2.2
Get returns the first result row.
Rows reach PHP as the bridge produced them, a map[string]any per row and a []map[string]any per result set, rather than being copied into a *model.Array. The VM reads both natively: foreach walks them, $row["col"] indexes them, and $row["extra"] = 1 writes to them, since a Go map is a reference type. The copy cost two allocations plus an interface box per column on every row of every query.
The one thing a map does not carry is column order, and neither did the *model.Array: the bridge's map had already lost it, so `foreach ($row as $column => $value)` has always produced an arbitrary order. It is now arbitrary per iteration rather than fixed per row; scripts that need a stable order should name their columns in the SELECT and index them.
func (*Database) GetAll ¶ added in v0.2.2
GetAll returns all result rows. See Get for the row representation.
func (*Database) Query ¶ added in v0.2.2
Query executes a statement with dynamically typed arguments.
func (*Database) Replace ¶ added in v0.2.2
Replace replaces a row using a dynamically typed named value.
func (*Database) Rollback ¶ added in v0.2.2
Rollback rolls back the active transaction and ends its span.
func (*Database) RowsAffected ¶ added in v0.2.2
RowsAffected returns the affected row count from the last write.
type DatabaseMigrate ¶ added in v0.2.3
type DatabaseMigrate struct {
// contains filtered or unexported fields
}
DatabaseMigrate loads and runs SQL migrations against a platform database.
func (*DatabaseMigrate) Load ¶ added in v0.2.3
func (m *DatabaseMigrate) Load(pattern string) error
Load reads migrations matching pattern from the runtime source filesystem.
func (*DatabaseMigrate) Run ¶ added in v0.2.3
func (m *DatabaseMigrate) Run(ctx context.Context) error
Run applies the loaded migrations. It is one span rather than one per file: migrations run at startup, where what matters is how long the schema took and whether it failed, not a row per statement.
type SessionManager ¶ added in v0.2.2
type SessionManager struct {
// SessionCookieName is the mutable name used to read and write the session
// cookie. PHP may change it with `$session->SessionCookieName = "sid"`.
SessionCookieName string
// contains filtered or unexported fields
}
SessionManager associates an HTTP-only cookie with data in SessionStorage. The cookie contains only an opaque, randomly generated session ID.
func NewSessionManager ¶ added in v0.2.2
func NewSessionManager(storage SessionStorage) (*SessionManager, error)
NewSessionManager creates a manager backed by storage.
func (*SessionManager) Get ¶ added in v0.2.2
func (s *SessionManager) Get(ctx context.Context) (string, error)
Get returns the user ID stored for the current session cookie.
type SessionStorage ¶ added in v0.2.2
type SessionStorage interface {
Load(ctx context.Context, id string) ([]byte, error)
Save(ctx context.Context, id string, data []byte) error
Delete(ctx context.Context, id string) error
Prune(ctx context.Context, maxAge time.Duration) error
}
SessionStorage persists opaque session data by ID.
type SessionStorageDisk ¶ added in v0.2.2
type SessionStorageDisk struct {
// contains filtered or unexported fields
}
SessionStorageDisk stores sessions in a local folder.
func NewSessionStorageDisk ¶ added in v0.2.2
func NewSessionStorageDisk(storagePaths ...string) (*SessionStorageDisk, error)
NewSessionStorageDisk creates the storage folder and verifies that it is writable. With no path, it uses the operating system's temporary directory.
func (*SessionStorageDisk) Delete ¶ added in v0.2.2
func (s *SessionStorageDisk) Delete(ctx context.Context, id string) error
Delete removes a session from disk.
type SessionStorageMemory ¶ added in v0.2.2
type SessionStorageMemory struct {
// contains filtered or unexported fields
}
SessionStorageMemory stores sessions in memory. Its contents are not durable.
func NewSessionStorageMemory ¶ added in v0.2.2
func NewSessionStorageMemory() *SessionStorageMemory
NewSessionStorageMemory creates empty in-memory session storage.
func (*SessionStorageMemory) Delete ¶ added in v0.2.2
func (s *SessionStorageMemory) Delete(ctx context.Context, id string) error
Delete removes a session from memory.
type SharedMemory ¶ added in v0.2.1
type SharedMemory struct {
// contains filtered or unexported fields
}
SharedMemory is a thread-safe in-memory key-value and atomic counter store exposed as SharedMemory to scripts.
func NewSharedMemory ¶ added in v0.2.1
func NewSharedMemory() *SharedMemory
NewSharedMemory returns a new empty SharedMemory instance.
func NewSharedMemoryBinding ¶ added in v0.2.1
func NewSharedMemoryBinding(ctx context.Context) (*SharedMemory, error)
NewSharedMemoryBinding is the constructor callback registered for SharedMemory.
func (*SharedMemory) Clear ¶ added in v0.2.1
func (s *SharedMemory) Clear(_ context.Context)
Clear resets all keys and counters.
func (*SharedMemory) Count ¶ added in v0.2.1
func (s *SharedMemory) Count(_ context.Context, key string) string
Count returns a counter as a formatted string.
func (*SharedMemory) Delete ¶ added in v0.2.1
func (s *SharedMemory) Delete(_ context.Context, key string) bool
Delete removes a key from storage.
func (*SharedMemory) Get ¶ added in v0.2.1
func (s *SharedMemory) Get(_ context.Context, key string) string
Get retrieves a string value by key, or returns empty string if missing.
func (*SharedMemory) Has ¶ added in v0.2.1
func (s *SharedMemory) Has(_ context.Context, key string) bool
Has checks if a key exists in data or counters.