package
0.0.0-20250104084734-6189fb222368
Repository: https://github.com/cmcd97/bytesize.git
Documentation: pkg.go.dev

# README

Model Package

This package provides CRUD operations for models in a PocketBase application.

Overview

The model package defines a Crud interface and provides functions to perform common database operations such as finding all records, finding a record by ID, and saving a record.

Interface

type Crud interface {
    models.Model
    GetUser() string
    Validate() error
}

Functions

FindAll

func FindAll[C Crud](model Crud, dao *daos.Dao, authRecord *models.Record) ([]C, error)

Finds all records of a given model that belong to the authenticated user.

FindById

func FindById(model Crud, dao *daos.Dao, authRecord *models.Record, id string) error

Finds a record by its ID and ensures it belongs to the authenticated user.

Save

func Save(model Crud, dao *daos.Dao) error

Validates and saves a model to the database.

Dependencies

Usage

Import the package and use the provided functions to interact with your models.

import (
    "github.com/yourusername/yourrepo/model"
    "github.com/pocketbase/pocketbase/daos"
    "github.com/pocketbase/pocketbase/models"
)