mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-23 20:27:42 +00:00
44 lines
808 B
Go
44 lines
808 B
Go
package data
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/jackc/pgx/v4/pgxpool"
|
|
)
|
|
|
|
var (
|
|
ErrRecordNotFound = errors.New("record not found")
|
|
)
|
|
|
|
type Models struct {
|
|
Accounts interface {
|
|
Upsert(a *Account) error
|
|
Delete(id int64) error
|
|
}
|
|
|
|
Devices interface {
|
|
Upsert(*Device) error
|
|
GetByAPNSToken(string) (*Device, error)
|
|
}
|
|
|
|
DevicesAccounts interface {
|
|
Associate(int64, int64) error
|
|
}
|
|
}
|
|
|
|
func NewModels(ctx context.Context, pool *pgxpool.Pool) *Models {
|
|
return &Models{
|
|
Accounts: &AccountModel{ctx, pool},
|
|
Devices: &DeviceModel{ctx, pool},
|
|
DevicesAccounts: &DeviceAccountModel{ctx, pool},
|
|
}
|
|
}
|
|
|
|
func NewMockModels() *Models {
|
|
return &Models{
|
|
Accounts: &MockAccountModel{},
|
|
Devices: &MockDeviceModel{},
|
|
DevicesAccounts: &MockDeviceAccountModel{},
|
|
}
|
|
}
|