gorm

package
v0.0.0-...-2f34b8b Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingSource = errors.New("missing source")
)

Functions

This section is empty.

Types

type AuthToken

type AuthToken struct {
	ID string `gorm:"primaryKey;autoIncrement:false"`

	CreatedAt time.Time
	UpdatedAt time.Time

	Owner   *User
	OwnerID string

	Label string
	Value string `gorm:"unique"`
}

type Branch

type Branch []model.SectionID

func (*Branch) Scan

func (b *Branch) Scan(value interface{}) error

func (*Branch) Value

func (b *Branch) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type Collection

type Collection struct {
	ID string `gorm:"primaryKey;autoIncrement:false"`

	CreatedAt time.Time
	UpdatedAt time.Time

	Owner   *User
	OwnerID string

	Label       string
	Description string

	Documents []*Document `gorm:"many2many:documents_collections;constraint:OnDelete:CASCADE"`

	PublicShares []*PublicShare `gorm:"many2many:public_shares_collections;"`

	Shares []*CollectionShare `gorm:"foreignKey:CollectionID;constraint:OnDelete:CASCADE"`
}

type CollectionShare

type CollectionShare struct {
	ID string `gorm:"primaryKey;autoIncrement:false"`

	CreatedAt time.Time
	UpdatedAt time.Time

	CollectionID string
	Collection   *Collection

	UserID string
	User   *User

	Level string
}

CollectionShare is the GORM model for collection shares.

type Document

type Document struct {
	ID        string `gorm:"primaryKey;autoIncrement:false"`
	ETag      string `gorm:"index"`
	CreatedAt time.Time
	UpdatedAt time.Time

	Owner   *User
	OwnerID string

	Source      string        `gorm:"unique;not null;index"`
	Sections    []*Section    `gorm:"constraint:OnDelete:CASCADE"`
	Collections []*Collection `gorm:"many2many:documents_collections;"`
	Content     []byte
}

type PublicShare

type PublicShare struct {
	ID string `gorm:"primaryKey;autoIncrement:false"`

	CreatedAt time.Time
	UpdatedAt time.Time

	Title       string
	Description string

	Token string `gorm:"unique"`

	Owner   *User
	OwnerID string

	Collections []*Collection `gorm:"many2many:public_shares_collections;"`
}

type Section

type Section struct {
	ID string `gorm:"primaryKey;autoIncrement:false"`

	CreatedAt time.Time
	UpdatedAt time.Time

	Document   *Document
	DocumentID string

	Parent   *Section
	ParentID *string

	// Fixed: Self-referencing relationship should only use ParentID as foreign key
	// ParentID references the ID field of the same Section table
	Sections []*Section `gorm:"foreignKey:ParentID;references:ID;constraint:OnDelete:CASCADE"`

	Branch *Branch
	Level  uint

	Start int
	End   int
}

type SnapshottedCollection

type SnapshottedCollection struct {
	ID          string
	OwnerID     string
	Label       string
	Description string
}

type SnapshottedDocument

type SnapshottedDocument struct {
	ID          string
	Owner       SnapshottedUser
	Source      string
	ETag        string
	Content     []byte
	Collections []SnapshottedCollection
	Sections    []SnapshottedSection
}

type SnapshottedSection

type SnapshottedSection struct {
	ID       string
	Branch   []string
	Start    int
	End      int
	Level    int
	Sections []SnapshottedSection
}

type SnapshottedUser

type SnapshottedUser struct {
	ID       string
	Provider string
	Subject  string
}

type Store

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

func NewStore

func NewStore(db *gorm.DB) *Store

func (*Store) CanReadCollection

func (s *Store) CanReadCollection(ctx context.Context, userID model.UserID, collectionID model.CollectionID) (bool, error)

CanReadCollection implements port.DocumentStore.

func (*Store) CanReadDocument

func (s *Store) CanReadDocument(ctx context.Context, userID model.UserID, documentID model.DocumentID) (bool, error)

CanReadDocument implements port.DocumentStore.

func (*Store) CanWriteCollection

func (s *Store) CanWriteCollection(ctx context.Context, userID model.UserID, collectionID model.CollectionID) (bool, error)

CanWriteCollection implements port.DocumentStore.

func (*Store) CanWriteDocument

func (s *Store) CanWriteDocument(ctx context.Context, userID model.UserID, documentID model.DocumentID) (bool, error)

CanWriteDocument implements port.DocumentStore.

func (*Store) CountReadableDocuments

func (s *Store) CountReadableDocuments(ctx context.Context, userID model.UserID) (int64, error)

CountReadableDocuments implements port.DocumentStore.

func (*Store) CreateAuthToken

func (s *Store) CreateAuthToken(ctx context.Context, token model.AuthToken) error

CreateAuthToken implements port.UserStore.

func (*Store) CreateCollection

func (s *Store) CreateCollection(ctx context.Context, ownerID model.UserID, label string) (model.PersistedCollection, error)

CreateCollection implements port.DocumentStore.

func (*Store) CreateCollectionShare

func (s *Store) CreateCollectionShare(ctx context.Context, collectionID model.CollectionID, userID model.UserID, level model.CollectionShareLevel) (model.PersistedCollectionShare, error)

CreateCollectionShare implements port.DocumentStore.

func (*Store) DeleteAuthToken

func (s *Store) DeleteAuthToken(ctx context.Context, tokenID model.AuthTokenID) error

DeleteAuthToken implements port.UserStore.

func (*Store) DeleteCollection

func (s *Store) DeleteCollection(ctx context.Context, id model.CollectionID) error

DeleteCollection implements port.DocumentStore.

func (*Store) DeleteCollectionShare

func (s *Store) DeleteCollectionShare(ctx context.Context, shareID model.CollectionShareID) error

DeleteCollectionShare implements port.DocumentStore.

func (*Store) DeleteDocumentByID

func (s *Store) DeleteDocumentByID(ctx context.Context, ids ...model.DocumentID) error

DeleteDocumentByID implements port.DocumentStore.

func (*Store) DeleteDocumentBySource

func (s *Store) DeleteDocumentBySource(ctx context.Context, ownerID model.UserID, source *url.URL) error

DeleteDocumentBySource implements port.DocumentStore.

func (*Store) DeletePublicShare

func (s *Store) DeletePublicShare(ctx context.Context, id model.PublicShareID) error

DeletePublicShare implements port.PublicShareStore.

func (*Store) FindAuthToken

func (s *Store) FindAuthToken(ctx context.Context, token string) (model.AuthToken, error)

FindAuthToken implements port.UserStore.

func (*Store) FindOrCreateUser

func (s *Store) FindOrCreateUser(ctx context.Context, provider, subject string) (model.User, error)

FindOrCreateUser implements port.UserStore.

func (*Store) FindPublicShareByToken

func (s *Store) FindPublicShareByToken(ctx context.Context, token string) (model.PersistedPublicShare, error)

FindPublicShareByToken implements port.PublicShareStore.

func (*Store) GenerateSnapshot

func (s *Store) GenerateSnapshot(ctx context.Context) (io.ReadCloser, error)

GenerateSnapshot implements backup.Snapshotable.

func (*Store) GetCollectionByID

func (s *Store) GetCollectionByID(ctx context.Context, id model.CollectionID, full bool) (model.PersistedCollection, error)

GetCollectionByID implements port.DocumentStore.

func (*Store) GetCollectionShares

func (s *Store) GetCollectionShares(ctx context.Context, collectionID model.CollectionID) ([]model.PersistedCollectionShare, error)

GetCollectionShares implements port.DocumentStore.

func (*Store) GetCollectionStats

func (s *Store) GetCollectionStats(ctx context.Context, id model.CollectionID) (*model.CollectionStats, error)

GetCollectionStats implements port.DocumentStore.

func (*Store) GetDocumentByID

func (s *Store) GetDocumentByID(ctx context.Context, id model.DocumentID) (model.PersistedDocument, error)

GetDocumentByID implements port.DocumentStore.

func (*Store) GetPublicShareByID

func (s *Store) GetPublicShareByID(ctx context.Context, id model.PublicShareID) (model.PersistedPublicShare, error)

GetPublicShareByID implements port.PublicShareStore.

func (*Store) GetSectionByID

func (s *Store) GetSectionByID(ctx context.Context, id model.SectionID) (model.Section, error)

GetSectionByID implements port.DocumentStore.

func (*Store) GetSectionsByIDs

func (s *Store) GetSectionsByIDs(ctx context.Context, ids []model.SectionID) (map[model.SectionID]model.Section, error)

GetSectionsByIDs implements port.DocumentStore.

func (*Store) GetUserAuthTokens

func (s *Store) GetUserAuthTokens(ctx context.Context, userID model.UserID) ([]model.AuthToken, error)

GetUserAuthTokens implements port.UserStore.

func (*Store) GetUserByID

func (s *Store) GetUserByID(ctx context.Context, userID model.UserID) (model.User, error)

GetUserByID implements port.UserStore.

func (*Store) QueryCollections

func (s *Store) QueryCollections(ctx context.Context, opts port.QueryCollectionsOptions) ([]model.PersistedCollection, error)

QueryCollections implements port.DocumentStore.

func (*Store) QueryDocuments

func (s *Store) QueryDocuments(ctx context.Context, opts port.QueryDocumentsOptions) ([]model.PersistedDocument, int64, error)

QueryDocuments implements port.DocumentStore.

func (*Store) QueryDocumentsByCollectionID

func (s *Store) QueryDocumentsByCollectionID(ctx context.Context, collectionID model.CollectionID, opts port.QueryDocumentsOptions) ([]model.PersistedDocument, int64, error)

QueryDocumentsByCollectionID implements port.DocumentStore.

func (*Store) QueryPublicShares

func (s *Store) QueryPublicShares(ctx context.Context, opts port.QueryPublicSharesOptions) ([]model.PersistedPublicShare, error)

QueryPublicShares implements port.PublicShareStore.

func (*Store) QueryUserReadableCollections

func (s *Store) QueryUserReadableCollections(ctx context.Context, userID model.UserID, opts port.QueryCollectionsOptions) ([]model.PersistedCollection, int64, error)

QueryUserReadableCollections implements port.DocumentStore.

func (*Store) QueryUserReadableDocuments

func (s *Store) QueryUserReadableDocuments(ctx context.Context, userID model.UserID, opts port.QueryDocumentsOptions) ([]model.PersistedDocument, int64, error)

QueryUserReadableDocuments implements port.DocumentStore.

func (*Store) QueryUserWritableCollections

func (s *Store) QueryUserWritableCollections(ctx context.Context, userID model.UserID, opts port.QueryCollectionsOptions) ([]model.PersistedCollection, int64, error)

QueryUserWritableCollections implements port.DocumentStore.

func (*Store) QueryUserWritableDocuments

func (s *Store) QueryUserWritableDocuments(ctx context.Context, userID model.UserID, opts port.QueryDocumentsOptions) ([]model.PersistedDocument, int64, error)

QueryUserWritableDocuments implements port.DocumentStore.

func (*Store) QueryUsers

func (s *Store) QueryUsers(ctx context.Context, opts port.QueryUsersOptions) ([]model.User, error)

QueryUsers implements port.UserStore.

func (*Store) RestoreSnapshot

func (s *Store) RestoreSnapshot(ctx context.Context, r io.Reader) error

RestoreSnapshot implements backup.Snapshotable.

func (*Store) SaveDocuments

func (s *Store) SaveDocuments(ctx context.Context, documents ...model.OwnedDocument) error

SaveDocuments implements port.DocumentStore.

func (*Store) SavePublicShare

func (s *Store) SavePublicShare(ctx context.Context, publicShare model.OwnedPublicShare) (model.PersistedPublicShare, error)

SavePublicShare implements port.PublicShareStore.

func (*Store) SaveUser

func (s *Store) SaveUser(ctx context.Context, user model.User) error

SaveUser implements port.UserStore.

func (*Store) SectionExists

func (s *Store) SectionExists(ctx context.Context, id model.SectionID) (bool, error)

SectionExists implements port.DocumentStore.

func (*Store) UpdateCollection

func (s *Store) UpdateCollection(ctx context.Context, id model.CollectionID, updates port.CollectionUpdates) (model.PersistedCollection, error)

UpdateCollection implements port.DocumentStore.

type User

type User struct {
	ID string `gorm:"primaryKey;autoIncrement:false"`

	CreatedAt time.Time
	UpdatedAt time.Time

	Subject  string `gorm:"index"`
	Provider string `gorm:"index"`

	DisplayName string
	Email       string `gorm:"unique"`

	AuthTokens  []*AuthToken  `gorm:"foreignKey:OwnerID;constraint:OnDelete:CASCADE;"`
	Documents   []*Document   `gorm:"foreignKey:OwnerID;constraint:OnDelete:CASCADE;"`
	Collections []*Collection `gorm:"foreignKey:OwnerID;constraint:OnDelete:CASCADE;"`

	Roles []*UserRole `gorm:"constraint:OnDelete:CASCADE;"`

	Active      bool
	Preferences *UserPreferences `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`
}

type UserPreferences

type UserPreferences struct {
	ID       uint   `gorm:"primaryKey"`
	UserID   string `gorm:"unique;index"`
	DarkMode bool
}

UserPreference is a separate table for storing user preferences

type UserRole

type UserRole struct {
	ID uint `gorm:"primaryKey"`

	CreatedAt time.Time

	User   *User
	UserID string `gorm:"index:user_role_index,unique"`

	Role string `gorm:"index:user_role_index,unique"`
}

Jump to

Keyboard shortcuts

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