Documentation
¶
Index ¶
- func JSON[T any](ptr *T) flsql.DTO
- func MakeMigrator(conn Connection, namespace string, steps migration.Steps[Connection]) migration.Migrator[Connection]
- func Timestamp(ptr *time.Time) flsql.DTO
- type CacheRepository
- func (r CacheRepository[ENT, ID]) BeginTx(ctx context.Context) (context.Context, error)
- func (r CacheRepository[ENT, ID]) CommitTx(ctx context.Context) error
- func (r CacheRepository[ENT, ID]) Entities() cache.EntityRepository[ENT, ID]
- func (r CacheRepository[ENT, ID]) Hits() cache.HitRepository[ID]
- func (r CacheRepository[ENT, ID]) Migrate(ctx context.Context) error
- func (r CacheRepository[ENT, ID]) RollbackTx(ctx context.Context) error
- type Connection
- type Locker
- type LockerFactory
- type Repository
- func (r Repository[ENT, ID]) BeginTx(ctx context.Context) (context.Context, error)
- func (r Repository[ENT, ID]) CommitTx(ctx context.Context) error
- func (r Repository[ENT, ID]) Create(ctx context.Context, ptr *ENT) (rErr error)
- func (r Repository[ENT, ID]) DeleteAll(ctx context.Context) (rErr error)
- func (r Repository[ENT, ID]) DeleteByID(ctx context.Context, id ID) (rErr error)
- func (r Repository[ENT, ID]) FindAll(ctx context.Context) iterkit.SeqE[ENT]
- func (r Repository[ENT, ID]) FindByID(ctx context.Context, id ID) (ENT, bool, error)
- func (r Repository[ENT, ID]) FindByIDs(ctx context.Context, ids ...ID) iterkit.SeqE[ENT]
- func (r Repository[ENT, ID]) RollbackTx(ctx context.Context) error
- func (r Repository[ENT, ID]) Save(ctx context.Context, ptr *ENT) (rErr error)
- func (r Repository[ENT, ID]) Update(ctx context.Context, ptr *ENT) (rErr error)
- type TaskerSchedulerLocks
- type TaskerSchedulerStateRepository
- func (r TaskerSchedulerStateRepository) Create(ctx context.Context, ptr *tasker.ScheduleState) error
- func (r TaskerSchedulerStateRepository) DeleteByID(ctx context.Context, id tasker.ScheduleID) error
- func (r TaskerSchedulerStateRepository) FindByID(ctx context.Context, id tasker.ScheduleID) (ent tasker.ScheduleState, found bool, err error)
- func (r TaskerSchedulerStateRepository) Migrate(ctx context.Context) error
- func (r TaskerSchedulerStateRepository) Update(ctx context.Context, ptr *tasker.ScheduleState) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeMigrator ¶
func MakeMigrator(conn Connection, namespace string, steps migration.Steps[Connection]) migration.Migrator[Connection]
Types ¶
type CacheRepository ¶
type CacheRepository[ENT, ID any] struct { Connection Connection // ID [required] is unique identifier. the table name prefix used to create the cache repository tables. // // Example: // ID: "foo" // -> "foo_cache_entities" // ID string // JSONDTOM [optional] is the mapping between an ENT type and a JSON DTO type, // which is used to encode entities within the entity repository. // This mapping is important because if the entity type changes during refactoring, // the previously cached data can still be correctly decoded using the JSON DTO. // This means you won’t need to delete cached data or worry about data corruption. // It provides a safeguard, ensuring smooth transitions without affecting stored data. JSONDTOM dtokit.Mapper[ENT] // IDA is the ID accessor, that explains how the ID field of the ENT can be accessed. IDA extid.Accessor[ENT, ID] // IDM is the mapping between ID and the string type which is used in the CacheRepository tables to represent the ID value. // If the ID is a string type, then this field can be ignored. IDM dtokit.MapperTo[ID, string] }
CacheRepository is a generic implementation for using mysql as a caching backend with `frameless/pkg/cache.Cache`. CacheRepository implements `cache.Repository[ENT,ID]`
func (CacheRepository[ENT, ID]) CommitTx ¶
func (r CacheRepository[ENT, ID]) CommitTx(ctx context.Context) error
func (CacheRepository[ENT, ID]) Entities ¶
func (r CacheRepository[ENT, ID]) Entities() cache.EntityRepository[ENT, ID]
func (CacheRepository[ENT, ID]) Hits ¶
func (r CacheRepository[ENT, ID]) Hits() cache.HitRepository[ID]
func (CacheRepository[ENT, ID]) Migrate ¶
func (r CacheRepository[ENT, ID]) Migrate(ctx context.Context) error
func (CacheRepository[ENT, ID]) RollbackTx ¶
func (r CacheRepository[ENT, ID]) RollbackTx(ctx context.Context) error
type Connection ¶
func Connect ¶
func Connect(dsn string) (Connection, error)
type Locker ¶ added in v0.4.0
type Locker struct { Name string Connection Connection }
Locker is a MariaDB-based shared mutex implementation.
Example ¶
package main import ( "context" "os" "go.llib.dev/frameless/adapter/mariadb" ) func main() { cm, err := mariadb.Connect(os.Getenv("DATABASE_URL")) if err != nil { panic(err) } l := mariadb.Locker{ Name: "my-lock", Connection: cm, } ctx, err := l.Lock(context.Background()) if err != nil { panic(err) } if err := l.Unlock(ctx); err != nil { panic(err) } }
type LockerFactory ¶ added in v0.4.0
type LockerFactory[Key comparable] struct { Connection Connection // Namespace [optional] allows you to make isolation between locks generated with the same key but for a different namesapce. Namespace string }
Example ¶
package main import ( "context" "log" "os" "go.llib.dev/frameless/adapter/mariadb" ) func main() { cm, err := mariadb.Connect(os.Getenv("DATABASE_URL")) if err != nil { log.Fatal(err) } lockerFactory := mariadb.LockerFactory[string]{Connection: cm} if err := lockerFactory.Migrate(context.Background()); err != nil { log.Fatal(err) } locker := lockerFactory.LockerFor("hello world") ctx, err := locker.Lock(context.Background()) if err != nil { log.Fatal(err) } if err := locker.Unlock(ctx); err != nil { log.Fatal(err) } }
func (LockerFactory[Key]) LockerFor ¶ added in v0.4.0
func (lf LockerFactory[Key]) LockerFor(key Key) guard.Locker
func (LockerFactory[Key]) Migrate ¶ added in v0.4.0
func (lf LockerFactory[Key]) Migrate(ctx context.Context) error
func (LockerFactory[Key]) NonBlockingLockerFor ¶ added in v0.5.0
func (lf LockerFactory[Key]) NonBlockingLockerFor(key Key) guard.NonBlockingLocker
type Repository ¶
type Repository[ENT, ID any] struct { Connection Connection Mapping flsql.Mapping[ENT, ID] }
Repository implements CRUD operations for a specific entity type in mariadb.
func MakeMigrationStateRepository ¶
func MakeMigrationStateRepository(conn Connection) Repository[migration.State, migration.StateID]
func (Repository[ENT, ID]) CommitTx ¶
func (r Repository[ENT, ID]) CommitTx(ctx context.Context) error
CommitTx implements the comproto.OnePhaseCommitter interface.
func (Repository[ENT, ID]) Create ¶
func (r Repository[ENT, ID]) Create(ctx context.Context, ptr *ENT) (rErr error)
func (Repository[ENT, ID]) DeleteAll ¶
func (r Repository[ENT, ID]) DeleteAll(ctx context.Context) (rErr error)
func (Repository[ENT, ID]) DeleteByID ¶
func (r Repository[ENT, ID]) DeleteByID(ctx context.Context, id ID) (rErr error)
func (Repository[ENT, ID]) FindAll ¶
func (r Repository[ENT, ID]) FindAll(ctx context.Context) iterkit.SeqE[ENT]
func (Repository[ENT, ID]) FindByID ¶
func (r Repository[ENT, ID]) FindByID(ctx context.Context, id ID) (ENT, bool, error)
func (Repository[ENT, ID]) FindByIDs ¶
func (r Repository[ENT, ID]) FindByIDs(ctx context.Context, ids ...ID) iterkit.SeqE[ENT]
func (Repository[ENT, ID]) RollbackTx ¶
func (r Repository[ENT, ID]) RollbackTx(ctx context.Context) error
RollbackTx implements the comproto.OnePhaseCommitter interface.
type TaskerSchedulerLocks ¶ added in v0.4.0
type TaskerSchedulerLocks struct{ Connection Connection }
func (TaskerSchedulerLocks) LockerFor ¶ added in v0.4.0
func (lf TaskerSchedulerLocks) LockerFor(id tasker.ScheduleID) guard.Locker
func (TaskerSchedulerLocks) Migrate ¶ added in v0.4.0
func (lf TaskerSchedulerLocks) Migrate(ctx context.Context) error
func (TaskerSchedulerLocks) NonBlockingLockerFor ¶ added in v0.5.0
func (lf TaskerSchedulerLocks) NonBlockingLockerFor(id tasker.ScheduleID) guard.NonBlockingLocker
type TaskerSchedulerStateRepository ¶ added in v0.4.0
type TaskerSchedulerStateRepository struct{ Connection Connection }
func (TaskerSchedulerStateRepository) Create ¶ added in v0.4.0
func (r TaskerSchedulerStateRepository) Create(ctx context.Context, ptr *tasker.ScheduleState) error
func (TaskerSchedulerStateRepository) DeleteByID ¶ added in v0.4.0
func (r TaskerSchedulerStateRepository) DeleteByID(ctx context.Context, id tasker.ScheduleID) error
func (TaskerSchedulerStateRepository) FindByID ¶ added in v0.4.0
func (r TaskerSchedulerStateRepository) FindByID(ctx context.Context, id tasker.ScheduleID) (ent tasker.ScheduleState, found bool, err error)
func (TaskerSchedulerStateRepository) Migrate ¶ added in v0.4.0
func (r TaskerSchedulerStateRepository) Migrate(ctx context.Context) error
func (TaskerSchedulerStateRepository) Update ¶ added in v0.4.0
func (r TaskerSchedulerStateRepository) Update(ctx context.Context, ptr *tasker.ScheduleState) error
Click to show internal directories.
Click to hide internal directories.