Documentation
¶
Index ¶
- Constants
- type NoResp
- type Option
- func WithBatchInsert[T, RESP any, V comparable](f func(ctx context.Context, values []T) error) Option[T, RESP, V]
- func WithBatchPageReq[T, RESP any, V comparable](f func(entityID string) page.PageReq) Option[T, RESP, V]
- func WithBatchPageRespConvertFunc[T, RESP any, V comparable](f func(resp *RESP) []T) Option[T, RESP, V]
- func WithDelete[T, RESP any, V comparable](f func(ctx context.Context, local T) error) Option[T, RESP, V]
- func WithDeleteAll[T, RESP any, V comparable](f func(ctx context.Context, entityID string) error) Option[T, RESP, V]
- func WithEqual[T, RESP any, V comparable](f func(a T, b T) bool) Option[T, RESP, V]
- func WithFullSyncLimit[T, RESP any, V comparable](limit int64) Option[T, RESP, V]
- func WithInsert[T, RESP any, V comparable](f func(ctx context.Context, value T) error) Option[T, RESP, V]
- func WithNotice[T, RESP any, V comparable](f func(ctx context.Context, state int, server, local T) error) Option[T, RESP, V]
- func WithReqApiRouter[T, RESP any, V comparable](router string) Option[T, RESP, V]
- func WithUUID[T, RESP any, V comparable](f func(value T) V) Option[T, RESP, V]
- func WithUpdate[T, RESP any, V comparable](f func(ctx context.Context, server T, local T) error) Option[T, RESP, V]
- type Syncer
- type VersionSynchronizer
Constants ¶
const ( Unchanged = 0 Insert = 1 Update = 2 Delete = 3 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option[T, RESP any, V comparable] func(*Syncer[T, RESP, V])
Option is a function that configures a Syncer.
func WithBatchInsert ¶
func WithBatchInsert[T, RESP any, V comparable](f func(ctx context.Context, values []T) error) Option[T, RESP, V]
WithBatchInsert sets the batchInsert function for the Syncer.
func WithBatchPageReq ¶
func WithBatchPageReq[T, RESP any, V comparable](f func(entityID string) page.PageReq) Option[T, RESP, V]
WithBatchPageReq sets the batchPageReq for the Syncer.
func WithBatchPageRespConvertFunc ¶
func WithBatchPageRespConvertFunc[T, RESP any, V comparable](f func(resp *RESP) []T) Option[T, RESP, V]
WithBatchPageRespConvertFunc sets the batchPageRespConvertFunc function for the Syncer.
func WithDelete ¶
func WithDelete[T, RESP any, V comparable](f func(ctx context.Context, local T) error) Option[T, RESP, V]
WithDelete sets the delete function for the Syncer.
func WithDeleteAll ¶
func WithDeleteAll[T, RESP any, V comparable](f func(ctx context.Context, entityID string) error) Option[T, RESP, V]
WithDeleteAll sets the deleteAll function for the Syncer.
func WithEqual ¶
func WithEqual[T, RESP any, V comparable](f func(a T, b T) bool) Option[T, RESP, V]
WithEqual sets the equal function for the Syncer.
func WithFullSyncLimit ¶
func WithFullSyncLimit[T, RESP any, V comparable](limit int64) Option[T, RESP, V]
WithFullSyncLimit sets the fullSyncLimit for the Syncer.
func WithInsert ¶
func WithInsert[T, RESP any, V comparable](f func(ctx context.Context, value T) error) Option[T, RESP, V]
WithInsert sets the insert function for the Syncer.
func WithNotice ¶
func WithNotice[T, RESP any, V comparable](f func(ctx context.Context, state int, server, local T) error) Option[T, RESP, V]
WithNotice sets the notice function for the Syncer.
func WithReqApiRouter ¶
func WithReqApiRouter[T, RESP any, V comparable](router string) Option[T, RESP, V]
WithReqApiRouter sets the reqApiRouter for the Syncer.
func WithUUID ¶
func WithUUID[T, RESP any, V comparable](f func(value T) V) Option[T, RESP, V]
WithUUID sets the uuid function for the Syncer.
func WithUpdate ¶
func WithUpdate[T, RESP any, V comparable](f func(ctx context.Context, server T, local T) error) Option[T, RESP, V]
WithUpdate sets the update function for the Syncer.
type Syncer ¶
type Syncer[T, RESP any, V comparable] struct { // contains filtered or unexported fields }
Syncer is a struct that holds functions for synchronizing data. It includes functions for inserting, updating, deleting, and notifying, as well as functions for generating unique IDs and checking equality of data items.
func New ¶
func New[T, RESP any, V comparable]( insert func(ctx context.Context, value T) error, delete func(ctx context.Context, value T) error, update func(ctx context.Context, server T, local T) error, uuid func(value T) V, equal func(a T, b T) bool, notice func(ctx context.Context, state int, server, local T) error, ) *Syncer[T, RESP, V]
New creates a new Syncer instance with the provided synchronization functions. This function requires several callback functions to handle different aspects of data synchronization: - insert: A function to insert new data. - delete: A function to delete existing data. - update: A function to update existing data. - uuid: A function to generate a unique identifier for each data item. - equal: A function to check if two data items are equal. - notice: A function to handle notifications during the sync process. Panics if insert, delete, update, or uuid functions are not provided.
func NewSyncer ¶
func NewSyncer[T, RESP any, V comparable](opts ...Option[T, RESP, V]) *Syncer[T, RESP, V]
NewSyncer creates a new Syncer with the provided options.
func (*Syncer[T, RESP, V]) Sync ¶
func (s *Syncer[T, RESP, V]) Sync(ctx context.Context, serverData []T, localData []T, notice func(ctx context.Context, state int, server, local T) error, skipDeletionAndNotice ...bool) (err error)
Sync synchronizes server data with local data. Sync synchronizes the data between the server and local storage. It takes a context, two slices of data (serverData and localData), a notice function to handle notifications during the sync process, and a variadic parameter skipDeletion to control deletion behavior.
type VersionSynchronizer ¶
type VersionSynchronizer[V, R any] struct { Ctx context.Context DB db_interface.VersionSyncModel TableName string EntityID string Key func(V) string Local func() ([]V, error) ServerVersion func() R Server func(version *model_struct.LocalVersionSync) (R, error) Full func(resp R) bool Version func(resp R) (string, uint64) Delete func(resp R) []string Update func(resp R) []V Insert func(resp R) []V ExtraData func(resp R) any ExtraDataProcessor func(ctx context.Context, data any) error Syncer func(server, local []V) error FullSyncer func(ctx context.Context) error FullID func(ctx context.Context) ([]string, error) IDOrderChanged func(resp R) bool }
func (*VersionSynchronizer[V, R]) CheckVersionSync ¶
func (o *VersionSynchronizer[V, R]) CheckVersionSync() error
func (*VersionSynchronizer[V, R]) IncrementalSync ¶
func (o *VersionSynchronizer[V, R]) IncrementalSync() error