Documentation
¶
Index ¶
- func DropAll(schemaURL string) error
- func Finalize() error
- func MigrateIfNeeded(schemaURL string) (bool, error)
- type Account
- type AccountRepository
- type CheckShortUrlKeyExistsParams
- type Click
- type ClickRepository
- type DBConf
- type DBTX
- type GetLinkByAccountIDAndShortURLKeyParams
- type InsertNewAccountParams
- type InsertNewClickParams
- type InsertNewLinkParams
- type Link
- type LinkRepository
- type Queries
- func (q *Queries) CheckPrefixExists(ctx context.Context, prefix string) (bool, error)
- func (q *Queries) CheckShortUrlKeyExists(ctx context.Context, arg CheckShortUrlKeyExistsParams) (bool, error)
- func (q *Queries) CheckUsernameExists(ctx context.Context, username string) (bool, error)
- func (q *Queries) GetAccountByPrefix(ctx context.Context, prefix string) (Account, error)
- func (q *Queries) GetAccountByUsername(ctx context.Context, username string) (Account, error)
- func (q *Queries) GetLinkByAccountIDAndShortURLKey(ctx context.Context, arg GetLinkByAccountIDAndShortURLKeyParams) (Link, error)
- func (q *Queries) InsertNewAccount(ctx context.Context, arg InsertNewAccountParams) error
- func (q *Queries) InsertNewClick(ctx context.Context, arg InsertNewClickParams) error
- func (q *Queries) InsertNewLink(ctx context.Context, arg InsertNewLinkParams) error
- func (q *Queries) UpdateAccountStatusByUsername(ctx context.Context, arg UpdateAccountStatusByUsernameParams) error
- func (q *Queries) UpdateLinkLongURL(ctx context.Context, arg UpdateLinkLongURLParams) error
- func (q *Queries) UpdateLinkStatus(ctx context.Context, arg UpdateLinkStatusParams) error
- func (q *Queries) UpdateLinkTrackingStatus(ctx context.Context, arg UpdateLinkTrackingStatusParams) error
- func (q *Queries) WithTx(tx *sql.Tx) *Queries
- type SQLStore
- type Store
- type UpdateAccountStatusByUsernameParams
- type UpdateLinkLongURLParams
- type UpdateLinkStatusParams
- type UpdateLinkTrackingStatusParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DropAll ¶
DropAll drops all tables in the database schemaURL is the path to the directory containing the migration files e.g. file://../db/migration
Returns an error if the drop failed
func MigrateIfNeeded ¶
MigrateIfNeeded checks if the database schema needs to be migrated and performs the migration if needed. schemaURL is the path to the directory containing the migration files e.g. file://../db/migration
Returns true if the migration was performed, false if no migration was needed
Types ¶
type Account ¶
type Account struct {
ID int32
// 3 characters, case-sensitive
Prefix string
Username string
Email string
// Hashed password
HashedPassword string
// A flag that enables/disables the account and its urls
Enabled bool
// Timestamp of creation
CreatedAt sql.NullTime
// Timestamp of last update
UpdatedAt sql.NullTime
}
Table holding Account information
type AccountRepository ¶
type AccountRepository interface {
CheckPrefixExists(ctx context.Context, prefix string) (bool, error)
CheckUsernameExists(ctx context.Context, username string) (bool, error)
GetAccountByPrefix(ctx context.Context, prefix string) (Account, error)
GetAccountByUsername(ctx context.Context, username string) (Account, error)
InsertNewAccount(ctx context.Context, arg InsertNewAccountParams) error
UpdateAccountStatusByUsername(ctx context.Context, arg UpdateAccountStatusByUsernameParams) error
}
type CheckShortUrlKeyExistsParams ¶
type CheckShortUrlKeyExistsParams struct {
ShortUrlKey sql.NullString
AccountID int32
}
type Click ¶
type Click struct {
ID int32
LinkID int32
// Timestamp of click
ClickDateTime sql.NullTime
UserAgent sql.NullString
IpAddress sql.NullString
}
Table holding click information
type ClickRepository ¶
type ClickRepository interface {
InsertNewClick(ctx context.Context, arg InsertNewClickParams) error
}
type GetLinkByAccountIDAndShortURLKeyParams ¶
type GetLinkByAccountIDAndShortURLKeyParams struct {
AccountID int32
ShortUrlKey sql.NullString
}
type InsertNewAccountParams ¶
type InsertNewClickParams ¶
type InsertNewClickParams struct {
LinkID int32
UserAgent sql.NullString
IpAddress sql.NullString
}
type InsertNewLinkParams ¶
type InsertNewLinkParams struct {
ShortUrlKey sql.NullString
AccountID int32
LongUrl string
}
type Link ¶
type Link struct {
ID int32
// 6 characters, case-sensitive
ShortUrlKey sql.NullString
AccountID int32
LongUrl string
// A flag to enable/disable the url redirection
Enabled bool
// A flag that enable/disable url tracking on redirection
TrackingEnabled bool
// Timestamp of creation
CreatedAt sql.NullTime
// Timestamp of last update
UpdatedAt sql.NullTime
}
Table holding Link information
type LinkRepository ¶
type LinkRepository interface {
CheckShortUrlKeyExists(ctx context.Context, arg CheckShortUrlKeyExistsParams) (bool, error)
GetLinkByAccountIDAndShortURLKey(ctx context.Context, arg GetLinkByAccountIDAndShortURLKeyParams) (Link, error)
InsertNewLink(ctx context.Context, arg InsertNewLinkParams) error
UpdateLinkLongURL(ctx context.Context, arg UpdateLinkLongURLParams) error
UpdateLinkStatus(ctx context.Context, arg UpdateLinkStatusParams) error
UpdateLinkTrackingStatus(ctx context.Context, arg UpdateLinkTrackingStatusParams) error
}
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func (*Queries) CheckPrefixExists ¶
func (*Queries) CheckShortUrlKeyExists ¶
func (*Queries) CheckUsernameExists ¶
func (*Queries) GetAccountByPrefix ¶
func (*Queries) GetAccountByUsername ¶
func (*Queries) GetLinkByAccountIDAndShortURLKey ¶
func (*Queries) InsertNewAccount ¶
func (q *Queries) InsertNewAccount(ctx context.Context, arg InsertNewAccountParams) error
func (*Queries) InsertNewClick ¶
func (q *Queries) InsertNewClick(ctx context.Context, arg InsertNewClickParams) error
func (*Queries) InsertNewLink ¶
func (q *Queries) InsertNewLink(ctx context.Context, arg InsertNewLinkParams) error
func (*Queries) UpdateAccountStatusByUsername ¶
func (q *Queries) UpdateAccountStatusByUsername(ctx context.Context, arg UpdateAccountStatusByUsernameParams) error
func (*Queries) UpdateLinkLongURL ¶
func (q *Queries) UpdateLinkLongURL(ctx context.Context, arg UpdateLinkLongURLParams) error
func (*Queries) UpdateLinkStatus ¶
func (q *Queries) UpdateLinkStatus(ctx context.Context, arg UpdateLinkStatusParams) error
func (*Queries) UpdateLinkTrackingStatus ¶
func (q *Queries) UpdateLinkTrackingStatus(ctx context.Context, arg UpdateLinkTrackingStatusParams) error
type SQLStore ¶
func GetStoreInstance ¶
GetStoreInstance returns a singleton instance of the SQLStore If the instance is not initialized, it will initialize it with the provided configuration If the instance is already initialized, it will return the existing instance
type Store ¶
type Store interface {
AccountRepository
LinkRepository
ClickRepository
Transactional(ctx context.Context, fn func(queries *Queries) error) error
}