mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
SQLite model refactoring (#3791)
* 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
This commit is contained in:
67
pkg/sqlite/timestamp.go
Normal file
67
pkg/sqlite/timestamp.go
Normal file
@@ -0,0 +1,67 @@
|
||||
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}
|
||||
}
|
||||
Reference in New Issue
Block a user