db

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

ABOUTME: Database connection management and initialization ABOUTME: Handles opening SQLite database with WAL mode at XDG path

ABOUTME: Database operations for follow-up tracking ABOUTME: Handles contact cadence, interaction logging, and follow-up queries

ABOUTME: Database schema definitions and migrations ABOUTME: Handles SQLite table creation and initialization

ABOUTME: Database operations for sync_state and sync_log tables ABOUTME: Manages sync status, tokens, and import tracking for external services

ABOUTME: Database operations for task management ABOUTME: Provides CRUD operations and queries for TaskObject

Index

Constants

View Source
const (
	ObjectTypeCompany = "Company"
	ObjectTypeContact = "Contact"
	ObjectTypeDeal    = "Deal"
)

Object type constants for CRM entities.

View Source
const (
	RelTypeWorksAt     = "works_at"
	RelTypeDealContact = "deal_contact"
	RelTypeDealCompany = "deal_company"
	RelTypeKnows       = "knows"
)

Relationship type constants for CRM relationships.

Variables

View Source
var (
	ErrObjectNotFound = errors.New("object not found")
	ErrInvalidObject  = errors.New("invalid object")
)
View Source
var (
	ErrRelationshipNotFound = errors.New("relationship not found")
	ErrInvalidRelationship  = errors.New("invalid relationship")
)

Functions

func AddDealNote

func AddDealNote(db *sql.DB, note *models.DealNote) error

func CheckSyncLogExists

func CheckSyncLogExists(db *sql.DB, sourceService, sourceID string) (bool, error)

CheckSyncLogExists checks if an entity has already been imported.

func CreateCompany

func CreateCompany(db *sql.DB, company *models.Company) error

func CreateContact

func CreateContact(db *sql.DB, contact *models.Contact) error

func CreateContactCadence

func CreateContactCadence(db *sql.DB, cadence *models.ContactCadence) error

CreateContactCadence creates or updates a contact's follow-up cadence.

func CreateDeal

func CreateDeal(db *sql.DB, deal *models.Deal) error

func CreateRelationship

func CreateRelationship(db *sql.DB, relationship *models.Relationship) error

func CreateSyncLog

func CreateSyncLog(db *sql.DB, id, sourceService, sourceID, entityType, entityID, metadata string) error

CreateSyncLog creates a sync log entry for an imported entity.

func CreateTask

func CreateTask(db *sql.DB, task *objects.TaskObject) error

CreateTask inserts a new task into the database.

func DeleteCompany

func DeleteCompany(db *sql.DB, id uuid.UUID) error

func DeleteContact

func DeleteContact(db *sql.DB, id uuid.UUID) error

func DeleteDeal

func DeleteDeal(db *sql.DB, id uuid.UUID) error

func DeleteRelationship

func DeleteRelationship(db *sql.DB, id uuid.UUID) error

func DeleteTask

func DeleteTask(db *sql.DB, id uuid.UUID) error

DeleteTask removes a task from the database.

func FindCompanies

func FindCompanies(db *sql.DB, query string, limit int) ([]models.Company, error)

func FindCompanyByName

func FindCompanyByName(db *sql.DB, name string) (*models.Company, error)

func FindContactRelationships

func FindContactRelationships(db *sql.DB, contactID uuid.UUID, relationshipType string) ([]models.Relationship, error)

func FindContacts

func FindContacts(db *sql.DB, query string, companyID *uuid.UUID, limit int) ([]models.Contact, error)

func FindDeals

func FindDeals(db *sql.DB, stage string, companyID *uuid.UUID, limit int) ([]models.Deal, error)

func FindRelationshipsBetween

func FindRelationshipsBetween(db *sql.DB, contactID1, contactID2 uuid.UUID) ([]models.Relationship, error)

func GetAllRelationships

func GetAllRelationships(db *sql.DB) ([]models.Relationship, error)

func GetCompany

func GetCompany(db *sql.DB, id uuid.UUID) (*models.Company, error)

func GetContact

func GetContact(db *sql.DB, id uuid.UUID) (*models.Contact, error)

func GetContactCadence

func GetContactCadence(db *sql.DB, contactID uuid.UUID) (*models.ContactCadence, error)

GetContactCadence retrieves cadence info for a contact.

func GetContactRelationships

func GetContactRelationships(db *sql.DB, contactID uuid.UUID) ([]models.Relationship, error)

func GetDeal

func GetDeal(db *sql.DB, id uuid.UUID) (*models.Deal, error)

func GetDealNotes

func GetDealNotes(db *sql.DB, dealID uuid.UUID) ([]models.DealNote, error)

func GetFollowupList

func GetFollowupList(db *sql.DB, limit int) ([]models.FollowupContact, error)

GetFollowupList returns contacts needing follow-up, sorted by priority.

func GetInteractionHistory

func GetInteractionHistory(db *sql.DB, contactID uuid.UUID, limit int) ([]models.InteractionLog, error)

GetInteractionHistory retrieves interaction history for a contact.

func GetRecentInteractions

func GetRecentInteractions(db *sql.DB, days int, limit int) ([]models.InteractionLog, error)

GetRecentInteractions gets all recent interactions across all contacts.

func GetRelationship

func GetRelationship(db *sql.DB, id uuid.UUID) (*models.Relationship, error)

func GetRelationshipsBetween

func GetRelationshipsBetween(db *sql.DB, contactID1, contactID2 uuid.UUID) ([]models.Relationship, error)

func GetTask

func GetTask(db *sql.DB, id uuid.UUID) (*objects.TaskObject, error)

GetTask retrieves a task by ID.

func InitSchema

func InitSchema(db *sql.DB) error

func ListDueSoonTasks

func ListDueSoonTasks(db *sql.DB, days int) ([]*objects.TaskObject, error)

ListDueSoonTasks returns tasks due within the specified number of days.

func ListOverdueTasks

func ListOverdueTasks(db *sql.DB) ([]*objects.TaskObject, error)

ListOverdueTasks returns all overdue tasks.

func ListTasks

func ListTasks(db *sql.DB, filter *TaskFilter) ([]*objects.TaskObject, error)

ListTasks retrieves tasks with optional filtering.

func ListTasksByRelatedRecord

func ListTasksByRelatedRecord(db *sql.DB, recordID uuid.UUID) ([]*objects.TaskObject, error)

ListTasksByRelatedRecord returns tasks linked to a specific record.

func LogInteraction

func LogInteraction(db *sql.DB, interaction *models.InteractionLog) error

LogInteraction records a new interaction and updates contact cadence.

func ObjectToCompany

func ObjectToCompany(obj *Object) (*models.Company, error)

ObjectToCompany converts an Office OS Object to a models.Company.

func ObjectToContact

func ObjectToContact(obj *Object) (*models.Contact, error)

ObjectToContact converts an Office OS Object to a models.Contact.

func ObjectToDeal

func ObjectToDeal(obj *Object) (*models.Deal, error)

ObjectToDeal converts an Office OS Object to a models.Deal.

func OpenDatabase

func OpenDatabase(path string) (*sql.DB, error)

func SetContactCadence

func SetContactCadence(db *sql.DB, contactID uuid.UUID, days int, strength string) error

SetContactCadence sets or updates a contact's cadence settings.

func UpdateCadenceAfterInteraction

func UpdateCadenceAfterInteraction(db *sql.DB, contactID uuid.UUID, timestamp time.Time) error

UpdateCadenceAfterInteraction updates cadence when interaction is logged.

func UpdateCompany

func UpdateCompany(db *sql.DB, id uuid.UUID, updates *models.Company) error

func UpdateContact

func UpdateContact(db *sql.DB, id uuid.UUID, updates *models.Contact) error

func UpdateContactLastContacted

func UpdateContactLastContacted(db *sql.DB, contactID uuid.UUID, timestamp time.Time) error

func UpdateDeal

func UpdateDeal(db *sql.DB, deal *models.Deal) error

func UpdateRelationship

func UpdateRelationship(db *sql.DB, id uuid.UUID, relType, ctx string) error

func UpdateSyncStatus

func UpdateSyncStatus(db *sql.DB, service, status string, errorMsg *string) error

UpdateSyncStatus updates the sync status for a service.

func UpdateSyncToken

func UpdateSyncToken(db *sql.DB, service, token string) error

UpdateSyncToken updates the sync token and last sync time for a service.

func UpdateTask

func UpdateTask(db *sql.DB, task *objects.TaskObject) error

UpdateTask updates an existing task.

Types

type Object

type Object struct {
	ID        string                 `json:"id"`
	Kind      string                 `json:"kind"`
	CreatedAt time.Time              `json:"created_at"`
	UpdatedAt time.Time              `json:"updated_at"`
	CreatedBy string                 `json:"created_by"`
	ACL       string                 `json:"acl"`  // JSON string
	Tags      string                 `json:"tags"` // JSON string
	Fields    map[string]interface{} `json:"fields"`
}

Object represents the core entity in Office OS.

func CompanyToObject

func CompanyToObject(company *models.Company) *Object

CompanyToObject converts a models.Company to an Office OS Object.

func ContactToObject

func ContactToObject(contact *models.Contact) *Object

ContactToObject converts a models.Contact to an Office OS Object.

func DealToObject

func DealToObject(deal *models.Deal) *Object

DealToObject converts a models.Deal to an Office OS Object.

type ObjectsRepository

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

ObjectsRepository provides CRUD operations for Office OS objects.

func NewObjectsRepository

func NewObjectsRepository(db *sql.DB) *ObjectsRepository

NewObjectsRepository creates a new objects repository.

func (*ObjectsRepository) Create

func (r *ObjectsRepository) Create(ctx context.Context, obj *Object) error

Create creates a new object in the database.

func (*ObjectsRepository) Delete

func (r *ObjectsRepository) Delete(ctx context.Context, id string) error

Delete deletes an object by ID.

func (*ObjectsRepository) Get

func (r *ObjectsRepository) Get(ctx context.Context, id string) (*Object, error)

Get retrieves an object by ID.

func (*ObjectsRepository) List

func (r *ObjectsRepository) List(ctx context.Context, objectKind string) ([]*Object, error)

List retrieves all objects, optionally filtered by kind.

func (*ObjectsRepository) Update

func (r *ObjectsRepository) Update(ctx context.Context, obj *Object) error

Update updates an existing object.

type Relationship

type Relationship struct {
	ID        string                 `json:"id"`
	SourceID  string                 `json:"source_id"`
	TargetID  string                 `json:"target_id"`
	Type      string                 `json:"type"`
	Metadata  map[string]interface{} `json:"metadata"`
	CreatedAt time.Time              `json:"created_at"`
	UpdatedAt time.Time              `json:"updated_at"`
}

Relationship represents a connection between two objects.

type RelationshipsRepository

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

RelationshipsRepository provides CRUD operations for relationships.

func NewRelationshipsRepository

func NewRelationshipsRepository(db *sql.DB) *RelationshipsRepository

NewRelationshipsRepository creates a new relationships repository.

func (*RelationshipsRepository) Create

Create creates a new relationship.

func (*RelationshipsRepository) Delete

func (r *RelationshipsRepository) Delete(ctx context.Context, id string) error

Delete deletes a relationship by ID.

func (*RelationshipsRepository) FindBetween

func (r *RelationshipsRepository) FindBetween(ctx context.Context, objectID1, objectID2 string) ([]*Relationship, error)

FindBetween retrieves all relationships between two objects (in either direction).

func (*RelationshipsRepository) FindBySource

func (r *RelationshipsRepository) FindBySource(ctx context.Context, sourceID string, relType string) ([]*Relationship, error)

FindBySource retrieves all relationships originating from a source object.

func (*RelationshipsRepository) FindByTarget

func (r *RelationshipsRepository) FindByTarget(ctx context.Context, targetID string, relType string) ([]*Relationship, error)

FindByTarget retrieves all relationships pointing to a target object.

func (*RelationshipsRepository) Get

Get retrieves a relationship by ID.

func (*RelationshipsRepository) List

func (r *RelationshipsRepository) List(ctx context.Context, relType string) ([]*Relationship, error)

List retrieves all relationships, optionally filtered by type.

func (*RelationshipsRepository) Update

Update updates an existing relationship.

type SyncState

type SyncState struct {
	Service       string
	LastSyncTime  *time.Time
	LastSyncToken *string
	Status        string
	ErrorMessage  *string
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

SyncState represents the sync state for a service.

func GetAllSyncStates

func GetAllSyncStates(db *sql.DB) ([]SyncState, error)

GetAllSyncStates retrieves the sync state for all services.

func GetSyncState

func GetSyncState(db *sql.DB, service string) (*SyncState, error)

GetSyncState retrieves the sync state for a service.

type TaskFilter

type TaskFilter struct {
	Status     string
	AssigneeID *uuid.UUID
	DueBefore  *time.Time
	DueAfter   *time.Time
}

TaskFilter defines filtering options for task queries.

Jump to

Keyboard shortcuts

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