Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
23 lines
644 B
Go
23 lines
644 B
Go
package model
|
|
|
|
import "github.com/QuantumNous/new-api/common"
|
|
|
|
// GetDBTimestamp returns a UNIX timestamp from database time.
|
|
// Falls back to application time on error.
|
|
func GetDBTimestamp() int64 {
|
|
var ts int64
|
|
var err error
|
|
switch {
|
|
case common.UsingMainDatabase(common.DatabaseTypePostgreSQL):
|
|
err = DB.Raw("SELECT EXTRACT(EPOCH FROM NOW())::bigint").Scan(&ts).Error
|
|
case common.UsingMainDatabase(common.DatabaseTypeSQLite):
|
|
err = DB.Raw("SELECT strftime('%s','now')").Scan(&ts).Error
|
|
default:
|
|
err = DB.Raw("SELECT UNIX_TIMESTAMP()").Scan(&ts).Error
|
|
}
|
|
if err != nil || ts <= 0 {
|
|
return common.GetTimestamp()
|
|
}
|
|
return ts
|
|
}
|