postgres

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Rules - DB Schema

CREATE TABLE IF NOT EXISTS rules (
    id          UUID PRIMARY KEY,
    group_id    UUID NOT NULL,
    name        VARCHAR(254) NOT NULL,
    description VARCHAR(1024),
    conditions  JSONB NOT NULL,
    operator    VARCHAR(3) NOT NULL,
    actions     JSONB NOT NULL
);

CREATE TABLE IF NOT EXISTS rules_things (
    rule_id   UUID NOT NULL REFERENCES rules(id) ON DELETE CASCADE,
    thing_id  UUID NOT NULL,
    PRIMARY KEY (rule_id, thing_id)
);

CREATE TABLE IF NOT EXISTS lua_scripts (
    id          UUID NOT NULL,
    group_id    UUID NOT NULL,
    script      VARCHAR(65535) NOT NULL,
    name        VARCHAR NOT NULL,
    description VARCHAR NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS lua_script_runs (
    id          UUID NOT NULL,
    script_id   UUID NOT NULL,
    rule_id     UUID NULL,
    thing_id    UUID NOT NULL,
    logs        JSONB NOT NULL,
    started_at  TIMESTAMPTZ NOT NULL,
    finished_at TIMESTAMPTZ NOT NULL,
    status      TEXT NOT NULL,
    error       TEXT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (script_id) REFERENCES lua_scripts (id) ON DELETE CASCADE,
    FOREIGN KEY (rule_id) REFERENCES rules (id) ON DELETE CASCADE
);

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(cfg Config) (*sqlx.DB, error)

Connect creates a connection to the PostgreSQL instance and applies any unapplied database migrations. A non-nil error is returned to indicate failure.

func NewRuleRepository

func NewRuleRepository(db dbutil.Database) rules.Repository

NewRuleRepository instantiates a PostgreSQL implementation of rule repository.

Types

type Config

type Config struct {
	Host        string
	Port        string
	User        string
	Pass        string
	Name        string
	SSLMode     string
	SSLCert     string
	SSLKey      string
	SSLRootCert string
}

Config defines the options that are used when connecting to a PostgreSQL instance.

Jump to

Keyboard shortcuts

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