mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
* Remove ID from PerformerPartial * Separate studio model from sqlite model * Separate movie model from sqlite model * Separate tag model from sqlite model * Separate saved filter model from sqlite model * Separate scene marker model from sqlite model * Separate gallery chapter model from sqlite model * Move ErrNoRows checks into sqlite, improve empty result error messages * Move SQLiteDate and SQLiteTimestamp to sqlite * Use changesetTranslator everywhere, refactor for consistency * Make PerformerStore.DestroyImage private * Fix rating on movie create
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"time"
|
|
)
|
|
|
|
// Timestamp represents a time stored in RFC3339 format.
|
|
type Timestamp struct {
|
|
Timestamp time.Time
|
|
}
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (t *Timestamp) Scan(value interface{}) error {
|
|
t.Timestamp = value.(time.Time)
|
|
return nil
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (t Timestamp) Value() (driver.Value, error) {
|
|
return t.Timestamp.Format(time.RFC3339), nil
|
|
}
|
|
|
|
// NullTimestamp represents a nullable time stored in RFC3339 format.
|
|
type NullTimestamp struct {
|
|
Timestamp time.Time
|
|
Valid bool
|
|
}
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (t *NullTimestamp) Scan(value interface{}) error {
|
|
var ok bool
|
|
t.Timestamp, ok = value.(time.Time)
|
|
if !ok {
|
|
t.Timestamp = time.Time{}
|
|
t.Valid = false
|
|
return nil
|
|
}
|
|
|
|
t.Valid = true
|
|
return nil
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (t NullTimestamp) Value() (driver.Value, error) {
|
|
if !t.Valid {
|
|
return nil, nil
|
|
}
|
|
|
|
return t.Timestamp.Format(time.RFC3339), nil
|
|
}
|
|
|
|
func (t NullTimestamp) TimePtr() *time.Time {
|
|
if !t.Valid {
|
|
return nil
|
|
}
|
|
|
|
timestamp := t.Timestamp
|
|
return ×tamp
|
|
}
|
|
|
|
func NullTimestampFromTimePtr(t *time.Time) NullTimestamp {
|
|
if t == nil {
|
|
return NullTimestamp{Valid: false}
|
|
}
|
|
return NullTimestamp{Timestamp: *t, Valid: true}
|
|
}
|