model

package
v0.0.0-...-6189fb2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: MIT Imports: 4 Imported by: 0

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"
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAll

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

func FindById

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

func Save

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

Types

type Crud

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

Jump to

Keyboard shortcuts

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