Documentation
¶
Index ¶
- Constants
- func IDString(id uint64) string
- func IsNotFoundError(err error) bool
- func NullTime(val *time.Time) sql.NullTime
- func Open(driverName string, dataSourceName, database string) (*sql.DB, string, error)
- func ParseUint(id string) (uint64, error)
- func RunListQuery[T any, TPointer RowPointer[T]](ctx context.Context, sql DB, take uint32, query string, args ...any) ([]TPointer, error)
- func RunListQueryWithOffset[T any, TPointer RowPointer[T]](ctx context.Context, sql DB, offset, take uint32, query string, args ...any) ([]TPointer, uint32, error)
- func String(val *string) string
- func TimePtr(val Time) *time.Time
- func Validate(m interface{}) error
- type DB
- type ID
- func (v ID) Invalid() bool
- func (v ID) IsZero() bool
- func (v ID) MarshalJSON() ([]byte, error)
- func (v *ID) Reset()
- func (v *ID) Scan(value any) error
- func (v *ID) Set(val string) error
- func (v ID) String() string
- func (v ID) UInt64() uint64
- func (v *ID) UnmarshalJSON(data []byte) error
- func (v ID) Valid() bool
- func (v ID) Value() (driver.Value, error)
- type IDArray
- type IDGenerator
- type Metadata
- type MigrationConfig
- type NULLString
- type Provider
- type Result
- type Row
- type RowPointer
- type RowScanner
- type Rows
- type SQLProvider
- type Strings
- type TableInfo
- type Time
- func (ns Time) Add(after time.Duration) Time
- func (ns Time) IsNil() bool
- func (ns Time) IsZero() bool
- func (ns Time) MarshalJSON() ([]byte, error)
- func (ns Time) Ptr() *time.Time
- func (ns *Time) Scan(value interface{}) error
- func (ns Time) String() string
- func (ns Time) UTC() time.Time
- func (ns Time) UnixMilli() int64
- func (ns *Time) UnmarshalJSON(data []byte) error
- func (ns Time) Value() (driver.Value, error)
- type Tx
- type Validator
Constants ¶
const ( MaxLenForName = 64 MaxLenForEmail = 160 MaxLenForShortURL = 256 )
Max values, common for strings
Variables ¶
This section is empty.
Functions ¶
func IsNotFoundError ¶
IsNotFoundError returns true, if error is NotFound
func RunListQuery ¶
func RunListQuery[T any, TPointer RowPointer[T]](ctx context.Context, sql DB, take uint32, query string, args ...any) ([]TPointer, error)
RunListQuery runs a query and returns a list of models
func RunListQueryWithOffset ¶
func RunListQueryWithOffset[T any, TPointer RowPointer[T]](ctx context.Context, sql DB, offset, take uint32, query string, args ...any) ([]TPointer, uint32, error)
RunListQueryWithOffset runs a query and returns a list of models, with the next offset, if there are more rows to fetch
Types ¶
type DB ¶
type DB interface {
// QueryContext executes a query that returns rows, typically a SELECT.
// The args are for any placeholder parameters in the query.
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
// QueryRowContext executes a query that is expected to return at most one row.
// QueryRowContext always returns a non-nil value. Errors are deferred until
// Row's Scan method is called.
// If the query selects no rows, the *Row's Scan will return ErrNoRows.
// Otherwise, the *Row's Scan scans the first selected row and discards
// the rest.
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
// ExecContext executes a query without returning any rows.
// The args are for any placeholder parameters in the query.
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
DB provides interface for Db operations
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID defines a type to convert between internal uint64 and external string representations of ID
func (ID) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface
func (*ID) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format.
type IDArray ¶
type IDArray []ID
IDArray defines a list of IDArray
type IDGenerator ¶
type IDGenerator interface {
// NextID generates a next unique ID.
NextID() ID
}
IDGenerator defines an interface to generate unique ID accross the cluster
type Metadata ¶
Metadata de/encodes the string map to/from a SQL string.
type MigrationConfig ¶
MigrationConfig defines migration configuration
type NULLString ¶
type NULLString string
NULLString de/encodes the string a SQL string.
func (*NULLString) Scan ¶
func (ns *NULLString) Scan(value interface{}) error
Scan implements the Scanner interface.
type Provider ¶
type Provider interface {
IDGenerator
// DB returns underlying DB connection
DB() DB
// Tx returns underlying DB transaction
Tx() Tx
// Close connection and release resources
Close() (err error)
BeginTx(ctx context.Context, opts *sql.TxOptions) (Provider, error)
}
Provider provides complete DB access
func NewProvider ¶
func NewProvider(provider, dataSourceName, dbName string, idGen flake.IDGenerator, migrateCfg *MigrationConfig) (Provider, error)
NewProvider creates a Provider instance
type Result ¶
type Result[T any, TPointer RowPointer[T]] struct { Rows []TPointer NextOffset uint32 }
Result describes the result of a list query
func (*Result[T, RowPointer]) RunQueryResult ¶
func (p *Result[T, RowPointer]) RunQueryResult(ctx context.Context, sql DB, offset, take uint32, query string, args ...any) error
RunQueryResult runs a query and populates the result with a list of models and the next offset, if there are more rows to fetch
type Row ¶
type Row interface {
// Scan copies the columns from the matched row into the values
// pointed at by dest. See the documentation on Rows.Scan for details.
// If more than one row matches the query,
// Scan uses the first row and discards the rest. If no row matches
// the query, Scan returns ErrNoRows.
Scan(dest ...any) error
// Err provides a way for wrapping packages to check for
// query errors without calling Scan.
// Err returns the error, if any, that was encountered while running the query.
// If this error is not nil, this error will also be returned from Scan.
Err() error
}
Row defines an interface for DB row
type RowPointer ¶
type RowPointer[T any] interface { *T RowScanner }
RowPointer defines a generic interface to scan a single row
type RowScanner ¶
RowScanner defines an interface to scan a single row
type Rows ¶
type Rows interface {
io.Closer
Row
// Next prepares the next result row for reading with the Scan method. It
// returns true on success, or false if there is no next result row or an error
// happened while preparing it. Err should be consulted to distinguish between
// the two cases.
//
// Every call to Scan, even the first one, must be preceded by a call to Next.
Next() bool
// NextResultSet prepares the next result set for reading. It reports whether
// there is further result sets, or false if there is no further result set
// or if there is an error advancing to it. The Err method should be consulted
// to distinguish between the two cases.
//
// After calling NextResultSet, the Next method should always be called before
// scanning. If there are further result sets they may not have rows in the result
// set.
NextResultSet() bool
}
Rows defines an interface for DB rows
type SQLProvider ¶
type SQLProvider struct {
// contains filtered or unexported fields
}
SQLProvider represents SQL client instance
func New ¶
func New(db *sql.DB, idGen flake.IDGenerator) (*SQLProvider, error)
New creates a Provider instance
func (*SQLProvider) BeginTx ¶
BeginTx starts a transaction.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginTx is canceled.
The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*SQLProvider) Close ¶
func (p *SQLProvider) Close() (err error)
Close connection and release resources
type Strings ¶
type Strings []string
Strings de/encodes the string slice to/from a SQL string.
type TableInfo ¶
type TableInfo struct {
Schema string
Name string
PrimaryKey string
Columns []string
Indexes []string
// SchemaName is FQN in schema.name format
SchemaName string `json:"-" yaml:"-"`
}
TableInfo defines a table info
func (*TableInfo) ColumnsList ¶
ColumnsList returns list of columns separated by comma
type Time ¶
Time implements sql.Time functionality and always returns UTC
func FromUnixMilli ¶
FromUnixMilli returns Time from Unix milliseconds elapsed since January 1, 1970 UTC.
func (Time) IsNil ¶
IsNil reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.
func (Time) IsZero ¶
IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.
func (Time) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. The time is a quoted string in RFC 3339 format, with sub-second precision added if present.
func (Time) String ¶
String returns string in RFC3339 format, if it's Zero time, an empty string is returned
func (Time) UnixMilli ¶
UnixMilli returns t as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
xdbcli
command
|
|
|
mocks
|
|
|
mockschema
Package mockschema is a generated GoMock package.
|
Package mockschema is a generated GoMock package. |
|
mockxdb
Package mockxdb is a generated GoMock package.
|
Package mockxdb is a generated GoMock package. |
|
pkg
|
|
|
cli
Package cli provides CLI app and global flags
|
Package cli provides CLI app and global flags |
|
cli/clisuite
Package clisuite to test CLI commands
|
Package clisuite to test CLI commands |
|
cli/schema
Package schema provides CLI commands
|
Package schema provides CLI commands |
|
print
Package print provides helper package to print objects.
|
Package print provides helper package to print objects. |
|
Package schema provides helper package to generate schema.
|
Package schema provides helper package to generate schema. |