supabase

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 5 Imported by: 0

README

NeoFlow Supabase Repository

Database layer for the NeoFlow automation service.

Overview

This package provides NeoFlow-specific data access for triggers and execution records.

The canonical schema lives in migrations/022_neoflow_schema.sql:

  • public.neoflow_triggers
  • public.neoflow_executions

File Structure

File Purpose
repository.go Repository interface and implementation
models.go Data models

Data Models

Trigger
type Trigger struct {
    ID            string          `json:"id"`
    UserID        string          `json:"user_id"`
    Name          string          `json:"name"`
    TriggerType   string          `json:"trigger_type"` // e.g. "cron", "event", "price_threshold"
    Schedule      string          `json:"schedule,omitempty"`
    Condition     json.RawMessage `json:"condition,omitempty"` // JSON (optional)
    Action        json.RawMessage `json:"action"`              // JSON (required)
    Enabled       bool            `json:"enabled"`
    LastExecution time.Time       `json:"last_execution,omitempty"`
    NextExecution time.Time       `json:"next_execution,omitempty"`
    CreatedAt     time.Time       `json:"created_at"`
}
Execution
type Execution struct {
    ID            string          `json:"id"`
    TriggerID     string          `json:"trigger_id"`
    ExecutedAt    time.Time       `json:"executed_at"`
    Success       bool            `json:"success"`
    Error         string          `json:"error,omitempty"`
    ActionType    string          `json:"action_type,omitempty"`
    ActionPayload json.RawMessage `json:"action_payload,omitempty"`
}

Repository Interface

type RepositoryInterface interface {
    // Trigger Operations
    GetTriggers(ctx context.Context, userID string) ([]Trigger, error)
    GetTrigger(ctx context.Context, id, userID string) (*Trigger, error)
    CreateTrigger(ctx context.Context, trigger *Trigger) error
    UpdateTrigger(ctx context.Context, trigger *Trigger) error
    DeleteTrigger(ctx context.Context, id, userID string) error
    SetTriggerEnabled(ctx context.Context, id, userID string, enabled bool) error
    GetPendingTriggers(ctx context.Context) ([]Trigger, error)

    // Execution Operations
    CreateExecution(ctx context.Context, exec *Execution) error
    GetExecutions(ctx context.Context, triggerID string, limit int) ([]Execution, error)
}

Usage

import neoflowsupabase "github.com/R3E-Network/service_layer/services/automation/supabase"

repo := neoflowsupabase.NewRepository(baseRepo)

// Create trigger
err := repo.CreateTrigger(ctx, &neoflowsupabase.Trigger{
    UserID:      userID,
    Name:        "Daily Report",
    TriggerType: "cron",
    Schedule:    "*/5 * * * *",
    Action:      json.RawMessage(`{"type":"webhook","url":"https://hooks.miniapps.com/hook"}`),
    Enabled:     true,
})

// Get pending triggers
pending, err := repo.GetPendingTriggers(ctx)

Documentation

Overview

Package supabase provides NeoFlow-specific database operations.

Package supabase provides NeoFlow-specific database operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Execution

type Execution struct {
	ID            string          `json:"id"`
	TriggerID     string          `json:"trigger_id"`
	ExecutedAt    time.Time       `json:"executed_at"`
	Success       bool            `json:"success"`
	Error         string          `json:"error,omitempty"`
	ActionType    string          `json:"action_type,omitempty"`
	ActionPayload json.RawMessage `json:"action_payload,omitempty"`
}

Execution represents an execution log entry.

type Repository

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

Repository provides NeoFlow-specific data access methods.

func NewRepository

func NewRepository(base *database.Repository) *Repository

NewRepository creates a new NeoFlow repository.

func (*Repository) CreateExecution

func (r *Repository) CreateExecution(ctx context.Context, exec *Execution) error

CreateExecution logs a trigger execution.

func (*Repository) CreateTrigger

func (r *Repository) CreateTrigger(ctx context.Context, trigger *Trigger) error

CreateTrigger inserts a new neoflow trigger.

func (*Repository) DeleteTrigger

func (r *Repository) DeleteTrigger(ctx context.Context, id, userID string) error

DeleteTrigger removes a trigger.

func (*Repository) GetExecutions

func (r *Repository) GetExecutions(ctx context.Context, triggerID string, limit int) ([]Execution, error)

GetExecutions lists executions for a trigger.

func (*Repository) GetPendingTriggers

func (r *Repository) GetPendingTriggers(ctx context.Context) ([]Trigger, error)

GetPendingTriggers retrieves triggers that need execution.

func (*Repository) GetTrigger

func (r *Repository) GetTrigger(ctx context.Context, id, userID string) (*Trigger, error)

GetTrigger returns a trigger by id scoped to a user.

func (*Repository) GetTriggers

func (r *Repository) GetTriggers(ctx context.Context, userID string) ([]Trigger, error)

GetTriggers retrieves neoflow triggers for a user.

func (*Repository) SetTriggerEnabled

func (r *Repository) SetTriggerEnabled(ctx context.Context, id, userID string, enabled bool) error

SetTriggerEnabled sets enabled flag.

func (*Repository) UpdateTrigger

func (r *Repository) UpdateTrigger(ctx context.Context, trigger *Trigger) error

UpdateTrigger updates a trigger by id.

type RepositoryInterface

type RepositoryInterface interface {
	// Trigger Operations
	GetTriggers(ctx context.Context, userID string) ([]Trigger, error)
	GetTrigger(ctx context.Context, id, userID string) (*Trigger, error)
	CreateTrigger(ctx context.Context, trigger *Trigger) error
	UpdateTrigger(ctx context.Context, trigger *Trigger) error
	DeleteTrigger(ctx context.Context, id, userID string) error
	SetTriggerEnabled(ctx context.Context, id, userID string, enabled bool) error
	GetPendingTriggers(ctx context.Context) ([]Trigger, error)
	// Execution Operations
	CreateExecution(ctx context.Context, exec *Execution) error
	GetExecutions(ctx context.Context, triggerID string, limit int) ([]Execution, error)
}

RepositoryInterface defines NeoFlow-specific data access methods. This interface allows for easy mocking in tests.

type Trigger

type Trigger struct {
	ID            string          `json:"id"`
	UserID        string          `json:"user_id"`
	Name          string          `json:"name"`
	TriggerType   string          `json:"trigger_type"`
	Schedule      string          `json:"schedule,omitempty"`
	Condition     json.RawMessage `json:"condition,omitempty"`
	Action        json.RawMessage `json:"action"`
	Enabled       bool            `json:"enabled"`
	LastExecution time.Time       `json:"last_execution,omitempty"`
	NextExecution time.Time       `json:"next_execution,omitempty"`
	CreatedAt     time.Time       `json:"created_at"`
}

Trigger represents an neoflow trigger.

Jump to

Keyboard shortcuts

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