2018-11-09 20:02:28 +00:00
// AUTOGENERATED BY gopkg.in/spacemonkeygo/dbx.v1
// DO NOT EDIT.
2018-12-05 14:03:23 +00:00
package dbx
2018-11-09 20:02:28 +00:00
import (
"bytes"
"context"
"database/sql"
"errors"
"fmt"
"reflect"
"regexp"
"strconv"
"strings"
"sync"
"time"
"unicode"
"github.com/lib/pq"
"github.com/mattn/go-sqlite3"
)
// Prevent conditional imports from causing build failures
var _ = strconv . Itoa
var _ = strings . LastIndex
var _ = fmt . Sprint
var _ sync . Mutex
var (
WrapErr = func ( err * Error ) error { return err }
Logger func ( format string , args ... interface { } )
errTooManyRows = errors . New ( "too many rows" )
errUnsupportedDriver = errors . New ( "unsupported driver" )
errEmptyUpdate = errors . New ( "empty update" )
)
func logError ( format string , args ... interface { } ) {
if Logger != nil {
Logger ( format , args ... )
}
}
type ErrorCode int
const (
ErrorCode_Unknown ErrorCode = iota
ErrorCode_UnsupportedDriver
ErrorCode_NoRows
ErrorCode_TxDone
ErrorCode_TooManyRows
ErrorCode_ConstraintViolation
ErrorCode_EmptyUpdate
)
type Error struct {
Err error
Code ErrorCode
Driver string
Constraint string
QuerySuffix string
}
func ( e * Error ) Error ( ) string {
return e . Err . Error ( )
}
func wrapErr ( e * Error ) error {
if WrapErr == nil {
return e
}
return WrapErr ( e )
}
func makeErr ( err error ) error {
if err == nil {
return nil
}
e := & Error { Err : err }
switch err {
case sql . ErrNoRows :
e . Code = ErrorCode_NoRows
case sql . ErrTxDone :
e . Code = ErrorCode_TxDone
}
return wrapErr ( e )
}
func unsupportedDriver ( driver string ) error {
return wrapErr ( & Error {
Err : errUnsupportedDriver ,
Code : ErrorCode_UnsupportedDriver ,
Driver : driver ,
} )
}
func emptyUpdate ( ) error {
return wrapErr ( & Error {
Err : errEmptyUpdate ,
Code : ErrorCode_EmptyUpdate ,
} )
}
func tooManyRows ( query_suffix string ) error {
return wrapErr ( & Error {
Err : errTooManyRows ,
Code : ErrorCode_TooManyRows ,
QuerySuffix : query_suffix ,
} )
}
func constraintViolation ( err error , constraint string ) error {
return wrapErr ( & Error {
Err : err ,
Code : ErrorCode_ConstraintViolation ,
Constraint : constraint ,
} )
}
type driver interface {
Exec ( query string , args ... interface { } ) ( sql . Result , error )
Query ( query string , args ... interface { } ) ( * sql . Rows , error )
QueryRow ( query string , args ... interface { } ) * sql . Row
}
var (
notAPointer = errors . New ( "destination not a pointer" )
lossyConversion = errors . New ( "lossy conversion" )
)
type DB struct {
* sql . DB
dbMethods
Hooks struct {
Now func ( ) time . Time
}
}
func Open ( driver , source string ) ( db * DB , err error ) {
var sql_db * sql . DB
switch driver {
case "postgres" :
sql_db , err = openpostgres ( source )
case "sqlite3" :
sql_db , err = opensqlite3 ( source )
default :
return nil , unsupportedDriver ( driver )
}
if err != nil {
return nil , makeErr ( err )
}
defer func ( sql_db * sql . DB ) {
if err != nil {
sql_db . Close ( )
}
} ( sql_db )
if err := sql_db . Ping ( ) ; err != nil {
return nil , makeErr ( err )
}
db = & DB {
DB : sql_db ,
}
db . Hooks . Now = time . Now
switch driver {
case "postgres" :
db . dbMethods = newpostgres ( db )
case "sqlite3" :
db . dbMethods = newsqlite3 ( db )
default :
return nil , unsupportedDriver ( driver )
}
return db , nil
}
func ( obj * DB ) Close ( ) ( err error ) {
return obj . makeErr ( obj . DB . Close ( ) )
}
func ( obj * DB ) Open ( ctx context . Context ) ( * Tx , error ) {
tx , err := obj . DB . Begin ( )
if err != nil {
return nil , obj . makeErr ( err )
}
return & Tx {
Tx : tx ,
txMethods : obj . wrapTx ( tx ) ,
} , nil
}
func ( obj * DB ) NewRx ( ) * Rx {
return & Rx { db : obj }
}
func DeleteAll ( ctx context . Context , db * DB ) ( int64 , error ) {
tx , err := db . Open ( ctx )
if err != nil {
return 0 , err
}
defer func ( ) {
if err == nil {
err = db . makeErr ( tx . Commit ( ) )
return
}
if err_rollback := tx . Rollback ( ) ; err_rollback != nil {
logError ( "delete-all: rollback failed: %v" , db . makeErr ( err_rollback ) )
}
} ( )
return tx . deleteAll ( ctx )
}
type Tx struct {
Tx * sql . Tx
txMethods
}
type dialectTx struct {
tx * sql . Tx
}
func ( tx * dialectTx ) Commit ( ) ( err error ) {
return makeErr ( tx . tx . Commit ( ) )
}
func ( tx * dialectTx ) Rollback ( ) ( err error ) {
return makeErr ( tx . tx . Rollback ( ) )
}
type postgresImpl struct {
db * DB
dialect __sqlbundle_postgres
driver driver
}
func ( obj * postgresImpl ) Rebind ( s string ) string {
return obj . dialect . Rebind ( s )
}
func ( obj * postgresImpl ) logStmt ( stmt string , args ... interface { } ) {
postgresLogStmt ( stmt , args ... )
}
func ( obj * postgresImpl ) makeErr ( err error ) error {
constraint , ok := obj . isConstraintError ( err )
if ok {
return constraintViolation ( err , constraint )
}
return makeErr ( err )
}
type postgresDB struct {
db * DB
* postgresImpl
}
func newpostgres ( db * DB ) * postgresDB {
return & postgresDB {
db : db ,
postgresImpl : & postgresImpl {
db : db ,
driver : db . DB ,
} ,
}
}
func ( obj * postgresDB ) Schema ( ) string {
2018-12-12 21:24:08 +00:00
return ` CREATE TABLE raws (
id bigserial NOT NULL ,
2018-11-09 20:02:28 +00:00
node_id text NOT NULL ,
2018-12-12 21:24:08 +00:00
interval_end_time timestamp with time zone NOT NULL ,
data_total bigint NOT NULL ,
data_type integer NOT NULL ,
2018-11-09 20:02:28 +00:00
created_at timestamp with time zone NOT NULL ,
updated_at timestamp with time zone NOT NULL ,
2018-12-12 21:24:08 +00:00
PRIMARY KEY ( id )
2018-11-09 20:02:28 +00:00
) ;
2018-12-12 21:24:08 +00:00
CREATE TABLE rollups (
id bigserial NOT NULL ,
2018-11-09 20:02:28 +00:00
node_id text NOT NULL ,
start_time timestamp with time zone NOT NULL ,
2018-12-12 21:24:08 +00:00
interval bigint NOT NULL ,
data_type integer NOT NULL ,
2018-11-09 20:02:28 +00:00
created_at timestamp with time zone NOT NULL ,
updated_at timestamp with time zone NOT NULL ,
2018-12-12 21:24:08 +00:00
PRIMARY KEY ( id )
2018-12-05 14:03:23 +00:00
) ;
CREATE TABLE timestamps (
name text NOT NULL ,
value timestamp with time zone NOT NULL ,
PRIMARY KEY ( name )
2018-11-09 20:02:28 +00:00
) ; `
}
func ( obj * postgresDB ) wrapTx ( tx * sql . Tx ) txMethods {
return & postgresTx {
dialectTx : dialectTx { tx : tx } ,
postgresImpl : & postgresImpl {
db : obj . db ,
driver : tx ,
} ,
}
}
type postgresTx struct {
dialectTx
* postgresImpl
}
func postgresLogStmt ( stmt string , args ... interface { } ) {
// TODO: render placeholders
if Logger != nil {
out := fmt . Sprintf ( "stmt: %s\nargs: %v\n" , stmt , pretty ( args ) )
Logger ( out )
}
}
type sqlite3Impl struct {
db * DB
dialect __sqlbundle_sqlite3
driver driver
}
func ( obj * sqlite3Impl ) Rebind ( s string ) string {
return obj . dialect . Rebind ( s )
}
func ( obj * sqlite3Impl ) logStmt ( stmt string , args ... interface { } ) {
sqlite3LogStmt ( stmt , args ... )
}
func ( obj * sqlite3Impl ) makeErr ( err error ) error {
constraint , ok := obj . isConstraintError ( err )
if ok {
return constraintViolation ( err , constraint )
}
return makeErr ( err )
}
type sqlite3DB struct {
db * DB
* sqlite3Impl
}
func newsqlite3 ( db * DB ) * sqlite3DB {
return & sqlite3DB {
db : db ,
sqlite3Impl : & sqlite3Impl {
db : db ,
driver : db . DB ,
} ,
}
}
func ( obj * sqlite3DB ) Schema ( ) string {
2018-12-12 21:24:08 +00:00
return ` CREATE TABLE raws (
id INTEGER NOT NULL ,
2018-11-09 20:02:28 +00:00
node_id TEXT NOT NULL ,
2018-12-12 21:24:08 +00:00
interval_end_time TIMESTAMP NOT NULL ,
data_total INTEGER NOT NULL ,
data_type INTEGER NOT NULL ,
2018-11-09 20:02:28 +00:00
created_at TIMESTAMP NOT NULL ,
updated_at TIMESTAMP NOT NULL ,
2018-12-12 21:24:08 +00:00
PRIMARY KEY ( id )
2018-11-09 20:02:28 +00:00
) ;
2018-12-12 21:24:08 +00:00
CREATE TABLE rollups (
id INTEGER NOT NULL ,
2018-11-09 20:02:28 +00:00
node_id TEXT NOT NULL ,
start_time TIMESTAMP NOT NULL ,
2018-12-12 21:24:08 +00:00
interval INTEGER NOT NULL ,
data_type INTEGER NOT NULL ,
2018-11-09 20:02:28 +00:00
created_at TIMESTAMP NOT NULL ,
updated_at TIMESTAMP NOT NULL ,
2018-12-12 21:24:08 +00:00
PRIMARY KEY ( id )
2018-12-05 14:03:23 +00:00
) ;
CREATE TABLE timestamps (
name TEXT NOT NULL ,
value TIMESTAMP NOT NULL ,
PRIMARY KEY ( name )
2018-11-09 20:02:28 +00:00
) ; `
}
func ( obj * sqlite3DB ) wrapTx ( tx * sql . Tx ) txMethods {
return & sqlite3Tx {
dialectTx : dialectTx { tx : tx } ,
sqlite3Impl : & sqlite3Impl {
db : obj . db ,
driver : tx ,
} ,
}
}
type sqlite3Tx struct {
dialectTx
* sqlite3Impl
}
func sqlite3LogStmt ( stmt string , args ... interface { } ) {
// TODO: render placeholders
if Logger != nil {
out := fmt . Sprintf ( "stmt: %s\nargs: %v\n" , stmt , pretty ( args ) )
Logger ( out )
}
}
type pretty [ ] interface { }
func ( p pretty ) Format ( f fmt . State , c rune ) {
fmt . Fprint ( f , "[" )
nextval :
for i , val := range p {
if i > 0 {
fmt . Fprint ( f , ", " )
}
rv := reflect . ValueOf ( val )
if rv . Kind ( ) == reflect . Ptr {
if rv . IsNil ( ) {
fmt . Fprint ( f , "NULL" )
continue
}
val = rv . Elem ( ) . Interface ( )
}
switch v := val . ( type ) {
case string :
fmt . Fprintf ( f , "%q" , v )
case time . Time :
fmt . Fprintf ( f , "%s" , v . Format ( time . RFC3339Nano ) )
case [ ] byte :
for _ , b := range v {
if ! unicode . IsPrint ( rune ( b ) ) {
fmt . Fprintf ( f , "%#x" , v )
continue nextval
}
}
fmt . Fprintf ( f , "%q" , v )
default :
fmt . Fprintf ( f , "%v" , v )
}
}
fmt . Fprint ( f , "]" )
}
2018-12-12 21:24:08 +00:00
type Raw struct {
Id int64
NodeId string
IntervalEndTime time . Time
DataTotal int64
DataType int
CreatedAt time . Time
UpdatedAt time . Time
}
func ( Raw ) _Table ( ) string { return "raws" }
type Raw_Update_Fields struct {
}
type Raw_Id_Field struct {
_set bool
_value int64
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func Raw_Id ( v int64 ) Raw_Id_Field {
return Raw_Id_Field { _set : true , _value : v }
}
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
func ( f Raw_Id_Field ) value ( ) interface { } {
if ! f . _set {
return nil
}
return f . _value
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( Raw_Id_Field ) _Column ( ) string { return "id" }
type Raw_NodeId_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value string
}
2018-12-12 21:24:08 +00:00
func Raw_NodeId ( v string ) Raw_NodeId_Field {
return Raw_NodeId_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Raw_NodeId_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Raw_NodeId_Field ) _Column ( ) string { return "node_id" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Raw_IntervalEndTime_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value time . Time
}
2018-12-12 21:24:08 +00:00
func Raw_IntervalEndTime ( v time . Time ) Raw_IntervalEndTime_Field {
return Raw_IntervalEndTime_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Raw_IntervalEndTime_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Raw_IntervalEndTime_Field ) _Column ( ) string { return "interval_end_time" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Raw_DataTotal_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value int64
}
2018-12-12 21:24:08 +00:00
func Raw_DataTotal ( v int64 ) Raw_DataTotal_Field {
return Raw_DataTotal_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Raw_DataTotal_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Raw_DataTotal_Field ) _Column ( ) string { return "data_total" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Raw_DataType_Field struct {
_set bool
_value int
}
func Raw_DataType ( v int ) Raw_DataType_Field {
return Raw_DataType_Field { _set : true , _value : v }
}
func ( f Raw_DataType_Field ) value ( ) interface { } {
if ! f . _set {
return nil
}
return f . _value
}
func ( Raw_DataType_Field ) _Column ( ) string { return "data_type" }
type Raw_CreatedAt_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value time . Time
}
2018-12-12 21:24:08 +00:00
func Raw_CreatedAt ( v time . Time ) Raw_CreatedAt_Field {
return Raw_CreatedAt_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Raw_CreatedAt_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Raw_CreatedAt_Field ) _Column ( ) string { return "created_at" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Raw_UpdatedAt_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value time . Time
}
2018-12-12 21:24:08 +00:00
func Raw_UpdatedAt ( v time . Time ) Raw_UpdatedAt_Field {
return Raw_UpdatedAt_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Raw_UpdatedAt_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Raw_UpdatedAt_Field ) _Column ( ) string { return "updated_at" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Rollup struct {
Id int64
2018-11-09 20:02:28 +00:00
NodeId string
StartTime time . Time
2018-12-12 21:24:08 +00:00
Interval int64
DataType int
2018-11-09 20:02:28 +00:00
CreatedAt time . Time
UpdatedAt time . Time
}
2018-12-12 21:24:08 +00:00
func ( Rollup ) _Table ( ) string { return "rollups" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Rollup_Update_Fields struct {
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
type Rollup_Id_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
2018-12-12 21:24:08 +00:00
_value int64
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func Rollup_Id ( v int64 ) Rollup_Id_Field {
return Rollup_Id_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Rollup_Id_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Rollup_Id_Field ) _Column ( ) string { return "id" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Rollup_NodeId_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
2018-12-12 21:24:08 +00:00
_value string
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func Rollup_NodeId ( v string ) Rollup_NodeId_Field {
return Rollup_NodeId_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Rollup_NodeId_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Rollup_NodeId_Field ) _Column ( ) string { return "node_id" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Rollup_StartTime_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value time . Time
}
2018-12-12 21:24:08 +00:00
func Rollup_StartTime ( v time . Time ) Rollup_StartTime_Field {
return Rollup_StartTime_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Rollup_StartTime_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Rollup_StartTime_Field ) _Column ( ) string { return "start_time" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Rollup_Interval_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value int64
}
2018-12-12 21:24:08 +00:00
func Rollup_Interval ( v int64 ) Rollup_Interval_Field {
return Rollup_Interval_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Rollup_Interval_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Rollup_Interval_Field ) _Column ( ) string { return "interval" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Rollup_DataType_Field struct {
_set bool
_value int
}
func Rollup_DataType ( v int ) Rollup_DataType_Field {
return Rollup_DataType_Field { _set : true , _value : v }
}
func ( f Rollup_DataType_Field ) value ( ) interface { } {
if ! f . _set {
return nil
}
return f . _value
}
func ( Rollup_DataType_Field ) _Column ( ) string { return "data_type" }
type Rollup_CreatedAt_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value time . Time
}
2018-12-12 21:24:08 +00:00
func Rollup_CreatedAt ( v time . Time ) Rollup_CreatedAt_Field {
return Rollup_CreatedAt_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Rollup_CreatedAt_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Rollup_CreatedAt_Field ) _Column ( ) string { return "created_at" }
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
type Rollup_UpdatedAt_Field struct {
2018-11-09 20:02:28 +00:00
_set bool
_value time . Time
}
2018-12-12 21:24:08 +00:00
func Rollup_UpdatedAt ( v time . Time ) Rollup_UpdatedAt_Field {
return Rollup_UpdatedAt_Field { _set : true , _value : v }
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( f Rollup_UpdatedAt_Field ) value ( ) interface { } {
2018-11-09 20:02:28 +00:00
if ! f . _set {
return nil
}
return f . _value
}
2018-12-12 21:24:08 +00:00
func ( Rollup_UpdatedAt_Field ) _Column ( ) string { return "updated_at" }
2018-11-09 20:02:28 +00:00
2018-12-05 14:03:23 +00:00
type Timestamps struct {
Name string
Value time . Time
}
func ( Timestamps ) _Table ( ) string { return "timestamps" }
type Timestamps_Update_Fields struct {
Value Timestamps_Value_Field
}
type Timestamps_Name_Field struct {
_set bool
_value string
}
func Timestamps_Name ( v string ) Timestamps_Name_Field {
return Timestamps_Name_Field { _set : true , _value : v }
}
func ( f Timestamps_Name_Field ) value ( ) interface { } {
if ! f . _set {
return nil
}
return f . _value
}
func ( Timestamps_Name_Field ) _Column ( ) string { return "name" }
type Timestamps_Value_Field struct {
_set bool
_value time . Time
}
func Timestamps_Value ( v time . Time ) Timestamps_Value_Field {
return Timestamps_Value_Field { _set : true , _value : v }
}
func ( f Timestamps_Value_Field ) value ( ) interface { } {
if ! f . _set {
return nil
}
return f . _value
}
func ( Timestamps_Value_Field ) _Column ( ) string { return "value" }
2018-11-09 20:02:28 +00:00
func toUTC ( t time . Time ) time . Time {
return t . UTC ( )
}
func toDate ( t time . Time ) time . Time {
// keep up the minute portion so that translations between timezones will
// continue to reflect properly.
return t . Truncate ( time . Minute )
}
//
// runtime support for building sql statements
//
type __sqlbundle_SQL interface {
Render ( ) string
private ( )
}
type __sqlbundle_Dialect interface {
Rebind ( sql string ) string
}
type __sqlbundle_RenderOp int
const (
__sqlbundle_NoFlatten __sqlbundle_RenderOp = iota
__sqlbundle_NoTerminate
)
func __sqlbundle_Render ( dialect __sqlbundle_Dialect , sql __sqlbundle_SQL , ops ... __sqlbundle_RenderOp ) string {
out := sql . Render ( )
flatten := true
terminate := true
for _ , op := range ops {
switch op {
case __sqlbundle_NoFlatten :
flatten = false
case __sqlbundle_NoTerminate :
terminate = false
}
}
if flatten {
out = __sqlbundle_flattenSQL ( out )
}
if terminate {
out += ";"
}
return dialect . Rebind ( out )
}
var __sqlbundle_reSpace = regexp . MustCompile ( ` \s+ ` )
func __sqlbundle_flattenSQL ( s string ) string {
return strings . TrimSpace ( __sqlbundle_reSpace . ReplaceAllString ( s , " " ) )
}
// this type is specially named to match up with the name returned by the
// dialect impl in the sql package.
type __sqlbundle_postgres struct { }
func ( p __sqlbundle_postgres ) Rebind ( sql string ) string {
out := make ( [ ] byte , 0 , len ( sql ) + 10 )
j := 1
for i := 0 ; i < len ( sql ) ; i ++ {
ch := sql [ i ]
if ch != '?' {
out = append ( out , ch )
continue
}
out = append ( out , '$' )
out = append ( out , strconv . Itoa ( j ) ... )
j ++
}
return string ( out )
}
// this type is specially named to match up with the name returned by the
// dialect impl in the sql package.
type __sqlbundle_sqlite3 struct { }
func ( s __sqlbundle_sqlite3 ) Rebind ( sql string ) string {
return sql
}
type __sqlbundle_Literal string
func ( __sqlbundle_Literal ) private ( ) { }
func ( l __sqlbundle_Literal ) Render ( ) string { return string ( l ) }
type __sqlbundle_Literals struct {
Join string
SQLs [ ] __sqlbundle_SQL
}
func ( __sqlbundle_Literals ) private ( ) { }
func ( l __sqlbundle_Literals ) Render ( ) string {
var out bytes . Buffer
first := true
for _ , sql := range l . SQLs {
if sql == nil {
continue
}
if ! first {
out . WriteString ( l . Join )
}
first = false
out . WriteString ( sql . Render ( ) )
}
return out . String ( )
}
type __sqlbundle_Condition struct {
// set at compile/embed time
Name string
Left string
Equal bool
Right string
// set at runtime
Null bool
}
func ( * __sqlbundle_Condition ) private ( ) { }
func ( c * __sqlbundle_Condition ) Render ( ) string {
switch {
case c . Equal && c . Null :
return c . Left + " is null"
case c . Equal && ! c . Null :
return c . Left + " = " + c . Right
case ! c . Equal && c . Null :
return c . Left + " is not null"
case ! c . Equal && ! c . Null :
return c . Left + " != " + c . Right
default :
panic ( "unhandled case" )
}
}
type __sqlbundle_Hole struct {
// set at compiile/embed time
Name string
// set at runtime
SQL __sqlbundle_SQL
}
func ( * __sqlbundle_Hole ) private ( ) { }
func ( h * __sqlbundle_Hole ) Render ( ) string { return h . SQL . Render ( ) }
//
// end runtime support for building sql statements
//
2018-12-05 14:03:23 +00:00
type Value_Row struct {
Value time . Time
}
func ( obj * postgresImpl ) Create_Timestamps ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ,
timestamps_value Timestamps_Value_Field ) (
timestamps * Timestamps , err error ) {
__name_val := timestamps_name . value ( )
__value_val := timestamps_value . value ( )
var __embed_stmt = __sqlbundle_Literal ( "INSERT INTO timestamps ( name, value ) VALUES ( ?, ? ) RETURNING timestamps.name, timestamps.value" )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __name_val , __value_val )
timestamps = & Timestamps { }
err = obj . driver . QueryRow ( __stmt , __name_val , __value_val ) . Scan ( & timestamps . Name , & timestamps . Value )
if err != nil {
return nil , obj . makeErr ( err )
}
return timestamps , nil
}
2018-12-12 21:24:08 +00:00
func ( obj * postgresImpl ) Create_Rollup ( ctx context . Context ,
rollup_node_id Rollup_NodeId_Field ,
rollup_start_time Rollup_StartTime_Field ,
rollup_interval Rollup_Interval_Field ,
rollup_data_type Rollup_DataType_Field ) (
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
__now := obj . db . Hooks . Now ( ) . UTC ( )
2018-12-12 21:24:08 +00:00
__node_id_val := rollup_node_id . value ( )
__start_time_val := rollup_start_time . value ( )
__interval_val := rollup_interval . value ( )
__data_type_val := rollup_data_type . value ( )
2018-11-09 20:02:28 +00:00
__created_at_val := __now
__updated_at_val := __now
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "INSERT INTO rollups ( node_id, start_time, interval, data_type, created_at, updated_at ) VALUES ( ?, ?, ?, ?, ?, ? ) RETURNING rollups.id, rollups.node_id, rollups.start_time, rollups.interval, rollups.data_type, rollups.created_at, rollups.updated_at" )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
2018-12-12 21:24:08 +00:00
obj . logStmt ( __stmt , __node_id_val , __start_time_val , __interval_val , __data_type_val , __created_at_val , __updated_at_val )
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
rollup = & Rollup { }
err = obj . driver . QueryRow ( __stmt , __node_id_val , __start_time_val , __interval_val , __data_type_val , __created_at_val , __updated_at_val ) . Scan ( & rollup . Id , & rollup . NodeId , & rollup . StartTime , & rollup . Interval , & rollup . DataType , & rollup . CreatedAt , & rollup . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return rollup , nil
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * postgresImpl ) Create_Raw ( ctx context . Context ,
raw_node_id Raw_NodeId_Field ,
raw_interval_end_time Raw_IntervalEndTime_Field ,
raw_data_total Raw_DataTotal_Field ,
raw_data_type Raw_DataType_Field ) (
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
__now := obj . db . Hooks . Now ( ) . UTC ( )
2018-12-12 21:24:08 +00:00
__node_id_val := raw_node_id . value ( )
__interval_end_time_val := raw_interval_end_time . value ( )
__data_total_val := raw_data_total . value ( )
__data_type_val := raw_data_type . value ( )
2018-11-09 20:02:28 +00:00
__created_at_val := __now
__updated_at_val := __now
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "INSERT INTO raws ( node_id, interval_end_time, data_total, data_type, created_at, updated_at ) VALUES ( ?, ?, ?, ?, ?, ? ) RETURNING raws.id, raws.node_id, raws.interval_end_time, raws.data_total, raws.data_type, raws.created_at, raws.updated_at" )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
2018-12-12 21:24:08 +00:00
obj . logStmt ( __stmt , __node_id_val , __interval_end_time_val , __data_total_val , __data_type_val , __created_at_val , __updated_at_val )
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
raw = & Raw { }
err = obj . driver . QueryRow ( __stmt , __node_id_val , __interval_end_time_val , __data_total_val , __data_type_val , __created_at_val , __updated_at_val ) . Scan ( & raw . Id , & raw . NodeId , & raw . IntervalEndTime , & raw . DataTotal , & raw . DataType , & raw . CreatedAt , & raw . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return raw , nil
2018-11-09 20:02:28 +00:00
}
2018-12-05 14:03:23 +00:00
func ( obj * postgresImpl ) Find_Timestamps_Value_By_Name ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ) (
row * Value_Row , err error ) {
var __embed_stmt = __sqlbundle_Literal ( "SELECT timestamps.value FROM timestamps WHERE timestamps.name = ?" )
var __values [ ] interface { }
__values = append ( __values , timestamps_name . value ( ) )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
row = & Value_Row { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & row . Value )
if err == sql . ErrNoRows {
return nil , nil
}
if err != nil {
return nil , obj . makeErr ( err )
}
return row , nil
}
2018-12-12 21:24:08 +00:00
func ( obj * postgresImpl ) Get_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ) (
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "SELECT rollups.id, rollups.node_id, rollups.start_time, rollups.interval, rollups.data_type, rollups.created_at, rollups.updated_at FROM rollups WHERE rollups.id = ?" )
2018-11-09 20:02:28 +00:00
var __values [ ] interface { }
2018-12-12 21:24:08 +00:00
__values = append ( __values , rollup_id . value ( ) )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
2018-12-12 21:24:08 +00:00
rollup = & Rollup { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & rollup . Id , & rollup . NodeId , & rollup . StartTime , & rollup . Interval , & rollup . DataType , & rollup . CreatedAt , & rollup . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return rollup , nil
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * postgresImpl ) All_Rollup_By_NodeId ( ctx context . Context ,
rollup_node_id Rollup_NodeId_Field ) (
rows [ ] * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "SELECT rollups.id, rollups.node_id, rollups.start_time, rollups.interval, rollups.data_type, rollups.created_at, rollups.updated_at FROM rollups WHERE rollups.node_id = ?" )
2018-11-09 20:02:28 +00:00
var __values [ ] interface { }
2018-12-12 21:24:08 +00:00
__values = append ( __values , rollup_node_id . value ( ) )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
2018-12-12 21:24:08 +00:00
__rows , err := obj . driver . Query ( __stmt , __values ... )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
defer __rows . Close ( )
for __rows . Next ( ) {
rollup := & Rollup { }
err = __rows . Scan ( & rollup . Id , & rollup . NodeId , & rollup . StartTime , & rollup . Interval , & rollup . DataType , & rollup . CreatedAt , & rollup . UpdatedAt )
if err != nil {
return nil , obj . makeErr ( err )
}
rows = append ( rows , rollup )
}
if err := __rows . Err ( ) ; err != nil {
return nil , obj . makeErr ( err )
}
return rows , nil
}
func ( obj * postgresImpl ) Get_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ) (
raw * Raw , err error ) {
var __embed_stmt = __sqlbundle_Literal ( "SELECT raws.id, raws.node_id, raws.interval_end_time, raws.data_total, raws.data_type, raws.created_at, raws.updated_at FROM raws WHERE raws.id = ?" )
var __values [ ] interface { }
__values = append ( __values , raw_id . value ( ) )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
raw = & Raw { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & raw . Id , & raw . NodeId , & raw . IntervalEndTime , & raw . DataTotal , & raw . DataType , & raw . CreatedAt , & raw . UpdatedAt )
if err != nil {
return nil , obj . makeErr ( err )
}
return raw , nil
}
func ( obj * postgresImpl ) All_Raw_By_NodeId ( ctx context . Context ,
raw_node_id Raw_NodeId_Field ) (
rows [ ] * Raw , err error ) {
var __embed_stmt = __sqlbundle_Literal ( "SELECT raws.id, raws.node_id, raws.interval_end_time, raws.data_total, raws.data_type, raws.created_at, raws.updated_at FROM raws WHERE raws.node_id = ?" )
var __values [ ] interface { }
__values = append ( __values , raw_node_id . value ( ) )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
__rows , err := obj . driver . Query ( __stmt , __values ... )
if err != nil {
return nil , obj . makeErr ( err )
}
defer __rows . Close ( )
for __rows . Next ( ) {
raw := & Raw { }
err = __rows . Scan ( & raw . Id , & raw . NodeId , & raw . IntervalEndTime , & raw . DataTotal , & raw . DataType , & raw . CreatedAt , & raw . UpdatedAt )
if err != nil {
return nil , obj . makeErr ( err )
}
rows = append ( rows , raw )
}
if err := __rows . Err ( ) ; err != nil {
return nil , obj . makeErr ( err )
}
return rows , nil
2018-11-09 20:02:28 +00:00
}
2018-12-05 14:03:23 +00:00
func ( obj * postgresImpl ) Update_Timestamps_By_Name ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ,
update Timestamps_Update_Fields ) (
timestamps * Timestamps , err error ) {
var __sets = & __sqlbundle_Hole { }
var __embed_stmt = __sqlbundle_Literals { Join : "" , SQLs : [ ] __sqlbundle_SQL { __sqlbundle_Literal ( "UPDATE timestamps SET " ) , __sets , __sqlbundle_Literal ( " WHERE timestamps.name = ? RETURNING timestamps.name, timestamps.value" ) } }
__sets_sql := __sqlbundle_Literals { Join : ", " }
var __values [ ] interface { }
var __args [ ] interface { }
if update . Value . _set {
__values = append ( __values , update . Value . value ( ) )
__sets_sql . SQLs = append ( __sets_sql . SQLs , __sqlbundle_Literal ( "value = ?" ) )
}
if len ( __sets_sql . SQLs ) == 0 {
return nil , emptyUpdate ( )
}
__args = append ( __args , timestamps_name . value ( ) )
__values = append ( __values , __args ... )
__sets . SQL = __sets_sql
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
timestamps = & Timestamps { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & timestamps . Name , & timestamps . Value )
if err == sql . ErrNoRows {
return nil , nil
}
if err != nil {
return nil , obj . makeErr ( err )
}
return timestamps , nil
}
2018-12-12 21:24:08 +00:00
func ( obj * postgresImpl ) Update_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ,
update Rollup_Update_Fields ) (
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
var __sets = & __sqlbundle_Hole { }
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literals { Join : "" , SQLs : [ ] __sqlbundle_SQL { __sqlbundle_Literal ( "UPDATE rollups SET " ) , __sets , __sqlbundle_Literal ( " WHERE rollups.id = ? RETURNING rollups.id, rollups.node_id, rollups.start_time, rollups.interval, rollups.data_type, rollups.created_at, rollups.updated_at" ) } }
2018-11-09 20:02:28 +00:00
__sets_sql := __sqlbundle_Literals { Join : ", " }
var __values [ ] interface { }
var __args [ ] interface { }
__now := obj . db . Hooks . Now ( ) . UTC ( )
__values = append ( __values , __now )
__sets_sql . SQLs = append ( __sets_sql . SQLs , __sqlbundle_Literal ( "updated_at = ?" ) )
2018-12-12 21:24:08 +00:00
__args = append ( __args , rollup_id . value ( ) )
2018-11-09 20:02:28 +00:00
__values = append ( __values , __args ... )
__sets . SQL = __sets_sql
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
2018-12-12 21:24:08 +00:00
rollup = & Rollup { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & rollup . Id , & rollup . NodeId , & rollup . StartTime , & rollup . Interval , & rollup . DataType , & rollup . CreatedAt , & rollup . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err == sql . ErrNoRows {
return nil , nil
}
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return rollup , nil
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * postgresImpl ) Update_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ,
update Raw_Update_Fields ) (
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
var __sets = & __sqlbundle_Hole { }
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literals { Join : "" , SQLs : [ ] __sqlbundle_SQL { __sqlbundle_Literal ( "UPDATE raws SET " ) , __sets , __sqlbundle_Literal ( " WHERE raws.id = ? RETURNING raws.id, raws.node_id, raws.interval_end_time, raws.data_total, raws.data_type, raws.created_at, raws.updated_at" ) } }
2018-11-09 20:02:28 +00:00
__sets_sql := __sqlbundle_Literals { Join : ", " }
var __values [ ] interface { }
var __args [ ] interface { }
__now := obj . db . Hooks . Now ( ) . UTC ( )
__values = append ( __values , __now )
__sets_sql . SQLs = append ( __sets_sql . SQLs , __sqlbundle_Literal ( "updated_at = ?" ) )
2018-12-12 21:24:08 +00:00
__args = append ( __args , raw_id . value ( ) )
2018-11-09 20:02:28 +00:00
__values = append ( __values , __args ... )
__sets . SQL = __sets_sql
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
2018-12-12 21:24:08 +00:00
raw = & Raw { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & raw . Id , & raw . NodeId , & raw . IntervalEndTime , & raw . DataTotal , & raw . DataType , & raw . CreatedAt , & raw . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err == sql . ErrNoRows {
return nil , nil
}
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return raw , nil
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * postgresImpl ) Delete_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ) (
2018-11-09 20:02:28 +00:00
deleted bool , err error ) {
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "DELETE FROM rollups WHERE rollups.id = ?" )
2018-11-09 20:02:28 +00:00
var __values [ ] interface { }
2018-12-12 21:24:08 +00:00
__values = append ( __values , rollup_id . value ( ) )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
__res , err := obj . driver . Exec ( __stmt , __values ... )
if err != nil {
return false , obj . makeErr ( err )
}
__count , err := __res . RowsAffected ( )
if err != nil {
return false , obj . makeErr ( err )
}
return __count > 0 , nil
}
2018-12-12 21:24:08 +00:00
func ( obj * postgresImpl ) Delete_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ) (
2018-11-09 20:02:28 +00:00
deleted bool , err error ) {
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "DELETE FROM raws WHERE raws.id = ?" )
2018-11-09 20:02:28 +00:00
var __values [ ] interface { }
2018-12-12 21:24:08 +00:00
__values = append ( __values , raw_id . value ( ) )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
__res , err := obj . driver . Exec ( __stmt , __values ... )
if err != nil {
return false , obj . makeErr ( err )
}
__count , err := __res . RowsAffected ( )
if err != nil {
return false , obj . makeErr ( err )
}
return __count > 0 , nil
}
func ( impl postgresImpl ) isConstraintError ( err error ) (
constraint string , ok bool ) {
if e , ok := err . ( * pq . Error ) ; ok {
if e . Code . Class ( ) == "23" {
return e . Constraint , true
}
}
return "" , false
}
func ( obj * postgresImpl ) deleteAll ( ctx context . Context ) ( count int64 , err error ) {
var __res sql . Result
var __count int64
2018-12-05 14:03:23 +00:00
__res , err = obj . driver . Exec ( "DELETE FROM timestamps;" )
if err != nil {
return 0 , obj . makeErr ( err )
}
__count , err = __res . RowsAffected ( )
if err != nil {
return 0 , obj . makeErr ( err )
}
count += __count
2018-12-12 21:24:08 +00:00
__res , err = obj . driver . Exec ( "DELETE FROM rollups;" )
2018-11-09 20:02:28 +00:00
if err != nil {
return 0 , obj . makeErr ( err )
}
__count , err = __res . RowsAffected ( )
if err != nil {
return 0 , obj . makeErr ( err )
}
count += __count
2018-12-12 21:24:08 +00:00
__res , err = obj . driver . Exec ( "DELETE FROM raws;" )
2018-11-09 20:02:28 +00:00
if err != nil {
return 0 , obj . makeErr ( err )
}
__count , err = __res . RowsAffected ( )
if err != nil {
return 0 , obj . makeErr ( err )
}
count += __count
return count , nil
}
2018-12-05 14:03:23 +00:00
func ( obj * sqlite3Impl ) Create_Timestamps ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ,
timestamps_value Timestamps_Value_Field ) (
timestamps * Timestamps , err error ) {
__name_val := timestamps_name . value ( )
__value_val := timestamps_value . value ( )
var __embed_stmt = __sqlbundle_Literal ( "INSERT INTO timestamps ( name, value ) VALUES ( ?, ? )" )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __name_val , __value_val )
__res , err := obj . driver . Exec ( __stmt , __name_val , __value_val )
if err != nil {
return nil , obj . makeErr ( err )
}
__pk , err := __res . LastInsertId ( )
if err != nil {
return nil , obj . makeErr ( err )
}
return obj . getLastTimestamps ( ctx , __pk )
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) Create_Rollup ( ctx context . Context ,
rollup_node_id Rollup_NodeId_Field ,
rollup_start_time Rollup_StartTime_Field ,
rollup_interval Rollup_Interval_Field ,
rollup_data_type Rollup_DataType_Field ) (
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
__now := obj . db . Hooks . Now ( ) . UTC ( )
2018-12-12 21:24:08 +00:00
__node_id_val := rollup_node_id . value ( )
__start_time_val := rollup_start_time . value ( )
__interval_val := rollup_interval . value ( )
__data_type_val := rollup_data_type . value ( )
2018-11-09 20:02:28 +00:00
__created_at_val := __now
__updated_at_val := __now
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "INSERT INTO rollups ( node_id, start_time, interval, data_type, created_at, updated_at ) VALUES ( ?, ?, ?, ?, ?, ? )" )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
2018-12-12 21:24:08 +00:00
obj . logStmt ( __stmt , __node_id_val , __start_time_val , __interval_val , __data_type_val , __created_at_val , __updated_at_val )
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
__res , err := obj . driver . Exec ( __stmt , __node_id_val , __start_time_val , __interval_val , __data_type_val , __created_at_val , __updated_at_val )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
__pk , err := __res . LastInsertId ( )
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return obj . getLastRollup ( ctx , __pk )
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) Create_Raw ( ctx context . Context ,
raw_node_id Raw_NodeId_Field ,
raw_interval_end_time Raw_IntervalEndTime_Field ,
raw_data_total Raw_DataTotal_Field ,
raw_data_type Raw_DataType_Field ) (
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
__now := obj . db . Hooks . Now ( ) . UTC ( )
2018-12-12 21:24:08 +00:00
__node_id_val := raw_node_id . value ( )
__interval_end_time_val := raw_interval_end_time . value ( )
__data_total_val := raw_data_total . value ( )
__data_type_val := raw_data_type . value ( )
2018-11-09 20:02:28 +00:00
__created_at_val := __now
__updated_at_val := __now
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "INSERT INTO raws ( node_id, interval_end_time, data_total, data_type, created_at, updated_at ) VALUES ( ?, ?, ?, ?, ?, ? )" )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
2018-12-12 21:24:08 +00:00
obj . logStmt ( __stmt , __node_id_val , __interval_end_time_val , __data_total_val , __data_type_val , __created_at_val , __updated_at_val )
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
__res , err := obj . driver . Exec ( __stmt , __node_id_val , __interval_end_time_val , __data_total_val , __data_type_val , __created_at_val , __updated_at_val )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
__pk , err := __res . LastInsertId ( )
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return obj . getLastRaw ( ctx , __pk )
2018-11-09 20:02:28 +00:00
}
2018-12-05 14:03:23 +00:00
func ( obj * sqlite3Impl ) Find_Timestamps_Value_By_Name ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ) (
row * Value_Row , err error ) {
var __embed_stmt = __sqlbundle_Literal ( "SELECT timestamps.value FROM timestamps WHERE timestamps.name = ?" )
var __values [ ] interface { }
__values = append ( __values , timestamps_name . value ( ) )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
row = & Value_Row { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & row . Value )
if err == sql . ErrNoRows {
return nil , nil
}
if err != nil {
return nil , obj . makeErr ( err )
}
return row , nil
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) Get_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ) (
rollup * Rollup , err error ) {
var __embed_stmt = __sqlbundle_Literal ( "SELECT rollups.id, rollups.node_id, rollups.start_time, rollups.interval, rollups.data_type, rollups.created_at, rollups.updated_at FROM rollups WHERE rollups.id = ?" )
var __values [ ] interface { }
__values = append ( __values , rollup_id . value ( ) )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
rollup = & Rollup { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & rollup . Id , & rollup . NodeId , & rollup . StartTime , & rollup . Interval , & rollup . DataType , & rollup . CreatedAt , & rollup . UpdatedAt )
if err != nil {
return nil , obj . makeErr ( err )
}
return rollup , nil
}
func ( obj * sqlite3Impl ) All_Rollup_By_NodeId ( ctx context . Context ,
rollup_node_id Rollup_NodeId_Field ) (
rows [ ] * Rollup , err error ) {
var __embed_stmt = __sqlbundle_Literal ( "SELECT rollups.id, rollups.node_id, rollups.start_time, rollups.interval, rollups.data_type, rollups.created_at, rollups.updated_at FROM rollups WHERE rollups.node_id = ?" )
var __values [ ] interface { }
__values = append ( __values , rollup_node_id . value ( ) )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
__rows , err := obj . driver . Query ( __stmt , __values ... )
if err != nil {
return nil , obj . makeErr ( err )
}
defer __rows . Close ( )
for __rows . Next ( ) {
rollup := & Rollup { }
err = __rows . Scan ( & rollup . Id , & rollup . NodeId , & rollup . StartTime , & rollup . Interval , & rollup . DataType , & rollup . CreatedAt , & rollup . UpdatedAt )
if err != nil {
return nil , obj . makeErr ( err )
}
rows = append ( rows , rollup )
}
if err := __rows . Err ( ) ; err != nil {
return nil , obj . makeErr ( err )
}
return rows , nil
}
func ( obj * sqlite3Impl ) Get_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ) (
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "SELECT raws.id, raws.node_id, raws.interval_end_time, raws.data_total, raws.data_type, raws.created_at, raws.updated_at FROM raws WHERE raws.id = ?" )
2018-11-09 20:02:28 +00:00
var __values [ ] interface { }
2018-12-12 21:24:08 +00:00
__values = append ( __values , raw_id . value ( ) )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
2018-12-12 21:24:08 +00:00
raw = & Raw { }
err = obj . driver . QueryRow ( __stmt , __values ... ) . Scan ( & raw . Id , & raw . NodeId , & raw . IntervalEndTime , & raw . DataTotal , & raw . DataType , & raw . CreatedAt , & raw . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return raw , nil
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) All_Raw_By_NodeId ( ctx context . Context ,
raw_node_id Raw_NodeId_Field ) (
rows [ ] * Raw , err error ) {
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "SELECT raws.id, raws.node_id, raws.interval_end_time, raws.data_total, raws.data_type, raws.created_at, raws.updated_at FROM raws WHERE raws.node_id = ?" )
2018-11-09 20:02:28 +00:00
var __values [ ] interface { }
2018-12-12 21:24:08 +00:00
__values = append ( __values , raw_node_id . value ( ) )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
2018-12-12 21:24:08 +00:00
__rows , err := obj . driver . Query ( __stmt , __values ... )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
defer __rows . Close ( )
for __rows . Next ( ) {
raw := & Raw { }
err = __rows . Scan ( & raw . Id , & raw . NodeId , & raw . IntervalEndTime , & raw . DataTotal , & raw . DataType , & raw . CreatedAt , & raw . UpdatedAt )
if err != nil {
return nil , obj . makeErr ( err )
}
rows = append ( rows , raw )
}
if err := __rows . Err ( ) ; err != nil {
return nil , obj . makeErr ( err )
}
return rows , nil
2018-11-09 20:02:28 +00:00
}
2018-12-05 14:03:23 +00:00
func ( obj * sqlite3Impl ) Update_Timestamps_By_Name ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ,
update Timestamps_Update_Fields ) (
timestamps * Timestamps , err error ) {
var __sets = & __sqlbundle_Hole { }
var __embed_stmt = __sqlbundle_Literals { Join : "" , SQLs : [ ] __sqlbundle_SQL { __sqlbundle_Literal ( "UPDATE timestamps SET " ) , __sets , __sqlbundle_Literal ( " WHERE timestamps.name = ?" ) } }
__sets_sql := __sqlbundle_Literals { Join : ", " }
var __values [ ] interface { }
var __args [ ] interface { }
if update . Value . _set {
__values = append ( __values , update . Value . value ( ) )
__sets_sql . SQLs = append ( __sets_sql . SQLs , __sqlbundle_Literal ( "value = ?" ) )
}
if len ( __sets_sql . SQLs ) == 0 {
return nil , emptyUpdate ( )
}
__args = append ( __args , timestamps_name . value ( ) )
__values = append ( __values , __args ... )
__sets . SQL = __sets_sql
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
timestamps = & Timestamps { }
_ , err = obj . driver . Exec ( __stmt , __values ... )
if err != nil {
return nil , obj . makeErr ( err )
}
var __embed_stmt_get = __sqlbundle_Literal ( "SELECT timestamps.name, timestamps.value FROM timestamps WHERE timestamps.name = ?" )
var __stmt_get = __sqlbundle_Render ( obj . dialect , __embed_stmt_get )
obj . logStmt ( "(IMPLIED) " + __stmt_get , __args ... )
err = obj . driver . QueryRow ( __stmt_get , __args ... ) . Scan ( & timestamps . Name , & timestamps . Value )
if err == sql . ErrNoRows {
return nil , nil
}
if err != nil {
return nil , obj . makeErr ( err )
}
return timestamps , nil
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) Update_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ,
update Rollup_Update_Fields ) (
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
var __sets = & __sqlbundle_Hole { }
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literals { Join : "" , SQLs : [ ] __sqlbundle_SQL { __sqlbundle_Literal ( "UPDATE rollups SET " ) , __sets , __sqlbundle_Literal ( " WHERE rollups.id = ?" ) } }
2018-11-09 20:02:28 +00:00
__sets_sql := __sqlbundle_Literals { Join : ", " }
var __values [ ] interface { }
var __args [ ] interface { }
__now := obj . db . Hooks . Now ( ) . UTC ( )
__values = append ( __values , __now )
__sets_sql . SQLs = append ( __sets_sql . SQLs , __sqlbundle_Literal ( "updated_at = ?" ) )
2018-12-12 21:24:08 +00:00
__args = append ( __args , rollup_id . value ( ) )
2018-11-09 20:02:28 +00:00
__values = append ( __values , __args ... )
__sets . SQL = __sets_sql
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
2018-12-12 21:24:08 +00:00
rollup = & Rollup { }
2018-11-09 20:02:28 +00:00
_ , err = obj . driver . Exec ( __stmt , __values ... )
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
var __embed_stmt_get = __sqlbundle_Literal ( "SELECT rollups.id, rollups.node_id, rollups.start_time, rollups.interval, rollups.data_type, rollups.created_at, rollups.updated_at FROM rollups WHERE rollups.id = ?" )
2018-11-09 20:02:28 +00:00
var __stmt_get = __sqlbundle_Render ( obj . dialect , __embed_stmt_get )
obj . logStmt ( "(IMPLIED) " + __stmt_get , __args ... )
2018-12-12 21:24:08 +00:00
err = obj . driver . QueryRow ( __stmt_get , __args ... ) . Scan ( & rollup . Id , & rollup . NodeId , & rollup . StartTime , & rollup . Interval , & rollup . DataType , & rollup . CreatedAt , & rollup . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err == sql . ErrNoRows {
return nil , nil
}
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return rollup , nil
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) Update_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ,
update Raw_Update_Fields ) (
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
var __sets = & __sqlbundle_Hole { }
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literals { Join : "" , SQLs : [ ] __sqlbundle_SQL { __sqlbundle_Literal ( "UPDATE raws SET " ) , __sets , __sqlbundle_Literal ( " WHERE raws.id = ?" ) } }
2018-11-09 20:02:28 +00:00
__sets_sql := __sqlbundle_Literals { Join : ", " }
var __values [ ] interface { }
var __args [ ] interface { }
__now := obj . db . Hooks . Now ( ) . UTC ( )
__values = append ( __values , __now )
__sets_sql . SQLs = append ( __sets_sql . SQLs , __sqlbundle_Literal ( "updated_at = ?" ) )
2018-12-12 21:24:08 +00:00
__args = append ( __args , raw_id . value ( ) )
2018-11-09 20:02:28 +00:00
__values = append ( __values , __args ... )
__sets . SQL = __sets_sql
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
2018-12-12 21:24:08 +00:00
raw = & Raw { }
2018-11-09 20:02:28 +00:00
_ , err = obj . driver . Exec ( __stmt , __values ... )
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
var __embed_stmt_get = __sqlbundle_Literal ( "SELECT raws.id, raws.node_id, raws.interval_end_time, raws.data_total, raws.data_type, raws.created_at, raws.updated_at FROM raws WHERE raws.id = ?" )
2018-11-09 20:02:28 +00:00
var __stmt_get = __sqlbundle_Render ( obj . dialect , __embed_stmt_get )
obj . logStmt ( "(IMPLIED) " + __stmt_get , __args ... )
2018-12-12 21:24:08 +00:00
err = obj . driver . QueryRow ( __stmt_get , __args ... ) . Scan ( & raw . Id , & raw . NodeId , & raw . IntervalEndTime , & raw . DataTotal , & raw . DataType , & raw . CreatedAt , & raw . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err == sql . ErrNoRows {
return nil , nil
}
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return raw , nil
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) Delete_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ) (
2018-11-09 20:02:28 +00:00
deleted bool , err error ) {
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "DELETE FROM rollups WHERE rollups.id = ?" )
2018-11-09 20:02:28 +00:00
var __values [ ] interface { }
2018-12-12 21:24:08 +00:00
__values = append ( __values , rollup_id . value ( ) )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
__res , err := obj . driver . Exec ( __stmt , __values ... )
if err != nil {
return false , obj . makeErr ( err )
}
__count , err := __res . RowsAffected ( )
if err != nil {
return false , obj . makeErr ( err )
}
return __count > 0 , nil
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) Delete_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ) (
2018-11-09 20:02:28 +00:00
deleted bool , err error ) {
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "DELETE FROM raws WHERE raws.id = ?" )
2018-11-09 20:02:28 +00:00
var __values [ ] interface { }
2018-12-12 21:24:08 +00:00
__values = append ( __values , raw_id . value ( ) )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , __values ... )
__res , err := obj . driver . Exec ( __stmt , __values ... )
if err != nil {
return false , obj . makeErr ( err )
}
__count , err := __res . RowsAffected ( )
if err != nil {
return false , obj . makeErr ( err )
}
return __count > 0 , nil
}
2018-12-05 14:03:23 +00:00
func ( obj * sqlite3Impl ) getLastTimestamps ( ctx context . Context ,
pk int64 ) (
timestamps * Timestamps , err error ) {
var __embed_stmt = __sqlbundle_Literal ( "SELECT timestamps.name, timestamps.value FROM timestamps WHERE _rowid_ = ?" )
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , pk )
timestamps = & Timestamps { }
err = obj . driver . QueryRow ( __stmt , pk ) . Scan ( & timestamps . Name , & timestamps . Value )
if err != nil {
return nil , obj . makeErr ( err )
}
return timestamps , nil
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) getLastRollup ( ctx context . Context ,
2018-11-09 20:02:28 +00:00
pk int64 ) (
2018-12-12 21:24:08 +00:00
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "SELECT rollups.id, rollups.node_id, rollups.start_time, rollups.interval, rollups.data_type, rollups.created_at, rollups.updated_at FROM rollups WHERE _rowid_ = ?" )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , pk )
2018-12-12 21:24:08 +00:00
rollup = & Rollup { }
err = obj . driver . QueryRow ( __stmt , pk ) . Scan ( & rollup . Id , & rollup . NodeId , & rollup . StartTime , & rollup . Interval , & rollup . DataType , & rollup . CreatedAt , & rollup . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return rollup , nil
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( obj * sqlite3Impl ) getLastRaw ( ctx context . Context ,
2018-11-09 20:02:28 +00:00
pk int64 ) (
2018-12-12 21:24:08 +00:00
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
var __embed_stmt = __sqlbundle_Literal ( "SELECT raws.id, raws.node_id, raws.interval_end_time, raws.data_total, raws.data_type, raws.created_at, raws.updated_at FROM raws WHERE _rowid_ = ?" )
2018-11-09 20:02:28 +00:00
var __stmt = __sqlbundle_Render ( obj . dialect , __embed_stmt )
obj . logStmt ( __stmt , pk )
2018-12-12 21:24:08 +00:00
raw = & Raw { }
err = obj . driver . QueryRow ( __stmt , pk ) . Scan ( & raw . Id , & raw . NodeId , & raw . IntervalEndTime , & raw . DataTotal , & raw . DataType , & raw . CreatedAt , & raw . UpdatedAt )
2018-11-09 20:02:28 +00:00
if err != nil {
return nil , obj . makeErr ( err )
}
2018-12-12 21:24:08 +00:00
return raw , nil
2018-11-09 20:02:28 +00:00
}
func ( impl sqlite3Impl ) isConstraintError ( err error ) (
constraint string , ok bool ) {
if e , ok := err . ( sqlite3 . Error ) ; ok {
if e . Code == sqlite3 . ErrConstraint {
msg := err . Error ( )
colon := strings . LastIndex ( msg , ":" )
if colon != - 1 {
return strings . TrimSpace ( msg [ colon : ] ) , true
}
return "" , true
}
}
return "" , false
}
func ( obj * sqlite3Impl ) deleteAll ( ctx context . Context ) ( count int64 , err error ) {
var __res sql . Result
var __count int64
2018-12-05 14:03:23 +00:00
__res , err = obj . driver . Exec ( "DELETE FROM timestamps;" )
if err != nil {
return 0 , obj . makeErr ( err )
}
__count , err = __res . RowsAffected ( )
if err != nil {
return 0 , obj . makeErr ( err )
}
count += __count
2018-12-12 21:24:08 +00:00
__res , err = obj . driver . Exec ( "DELETE FROM rollups;" )
2018-11-09 20:02:28 +00:00
if err != nil {
return 0 , obj . makeErr ( err )
}
__count , err = __res . RowsAffected ( )
if err != nil {
return 0 , obj . makeErr ( err )
}
count += __count
2018-12-12 21:24:08 +00:00
__res , err = obj . driver . Exec ( "DELETE FROM raws;" )
2018-11-09 20:02:28 +00:00
if err != nil {
return 0 , obj . makeErr ( err )
}
__count , err = __res . RowsAffected ( )
if err != nil {
return 0 , obj . makeErr ( err )
}
count += __count
return count , nil
}
type Rx struct {
db * DB
tx * Tx
}
func ( rx * Rx ) UnsafeTx ( ctx context . Context ) ( unsafe_tx * sql . Tx , err error ) {
tx , err := rx . getTx ( ctx )
if err != nil {
return nil , err
}
return tx . Tx , nil
}
func ( rx * Rx ) getTx ( ctx context . Context ) ( tx * Tx , err error ) {
if rx . tx == nil {
if rx . tx , err = rx . db . Open ( ctx ) ; err != nil {
return nil , err
}
}
return rx . tx , nil
}
func ( rx * Rx ) Rebind ( s string ) string {
return rx . db . Rebind ( s )
}
func ( rx * Rx ) Commit ( ) ( err error ) {
if rx . tx != nil {
err = rx . tx . Commit ( )
rx . tx = nil
}
return err
}
func ( rx * Rx ) Rollback ( ) ( err error ) {
if rx . tx != nil {
err = rx . tx . Rollback ( )
rx . tx = nil
}
return err
}
2018-12-12 21:24:08 +00:00
func ( rx * Rx ) All_Raw_By_NodeId ( ctx context . Context ,
raw_node_id Raw_NodeId_Field ) (
rows [ ] * Raw , err error ) {
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
return tx . All_Raw_By_NodeId ( ctx , raw_node_id )
}
func ( rx * Rx ) All_Rollup_By_NodeId ( ctx context . Context ,
rollup_node_id Rollup_NodeId_Field ) (
rows [ ] * Rollup , err error ) {
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
return tx . All_Rollup_By_NodeId ( ctx , rollup_node_id )
}
func ( rx * Rx ) Create_Raw ( ctx context . Context ,
raw_node_id Raw_NodeId_Field ,
raw_interval_end_time Raw_IntervalEndTime_Field ,
raw_data_total Raw_DataTotal_Field ,
raw_data_type Raw_DataType_Field ) (
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
2018-12-12 21:24:08 +00:00
return tx . Create_Raw ( ctx , raw_node_id , raw_interval_end_time , raw_data_total , raw_data_type )
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( rx * Rx ) Create_Rollup ( ctx context . Context ,
rollup_node_id Rollup_NodeId_Field ,
rollup_start_time Rollup_StartTime_Field ,
rollup_interval Rollup_Interval_Field ,
rollup_data_type Rollup_DataType_Field ) (
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
2018-12-12 21:24:08 +00:00
return tx . Create_Rollup ( ctx , rollup_node_id , rollup_start_time , rollup_interval , rollup_data_type )
2018-11-09 20:02:28 +00:00
}
2018-12-05 14:03:23 +00:00
func ( rx * Rx ) Create_Timestamps ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ,
timestamps_value Timestamps_Value_Field ) (
timestamps * Timestamps , err error ) {
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
return tx . Create_Timestamps ( ctx , timestamps_name , timestamps_value )
}
2018-12-12 21:24:08 +00:00
func ( rx * Rx ) Delete_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ) (
2018-11-09 20:02:28 +00:00
deleted bool , err error ) {
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
2018-12-12 21:24:08 +00:00
return tx . Delete_Raw_By_Id ( ctx , raw_id )
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( rx * Rx ) Delete_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ) (
2018-11-09 20:02:28 +00:00
deleted bool , err error ) {
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
2018-12-12 21:24:08 +00:00
return tx . Delete_Rollup_By_Id ( ctx , rollup_id )
2018-11-09 20:02:28 +00:00
}
2018-12-05 14:03:23 +00:00
func ( rx * Rx ) Find_Timestamps_Value_By_Name ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ) (
row * Value_Row , err error ) {
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
return tx . Find_Timestamps_Value_By_Name ( ctx , timestamps_name )
}
2018-12-12 21:24:08 +00:00
func ( rx * Rx ) Get_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ) (
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
2018-12-12 21:24:08 +00:00
return tx . Get_Raw_By_Id ( ctx , raw_id )
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( rx * Rx ) Get_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ) (
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
2018-12-12 21:24:08 +00:00
return tx . Get_Rollup_By_Id ( ctx , rollup_id )
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( rx * Rx ) Update_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ,
update Raw_Update_Fields ) (
raw * Raw , err error ) {
2018-11-09 20:02:28 +00:00
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
2018-12-12 21:24:08 +00:00
return tx . Update_Raw_By_Id ( ctx , raw_id , update )
2018-11-09 20:02:28 +00:00
}
2018-12-12 21:24:08 +00:00
func ( rx * Rx ) Update_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ,
update Rollup_Update_Fields ) (
rollup * Rollup , err error ) {
2018-11-09 20:02:28 +00:00
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
2018-12-12 21:24:08 +00:00
return tx . Update_Rollup_By_Id ( ctx , rollup_id , update )
2018-11-09 20:02:28 +00:00
}
2018-12-05 14:03:23 +00:00
func ( rx * Rx ) Update_Timestamps_By_Name ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ,
update Timestamps_Update_Fields ) (
timestamps * Timestamps , err error ) {
var tx * Tx
if tx , err = rx . getTx ( ctx ) ; err != nil {
return
}
return tx . Update_Timestamps_By_Name ( ctx , timestamps_name , update )
}
2018-11-09 20:02:28 +00:00
type Methods interface {
2018-12-12 21:24:08 +00:00
All_Raw_By_NodeId ( ctx context . Context ,
raw_node_id Raw_NodeId_Field ) (
rows [ ] * Raw , err error )
All_Rollup_By_NodeId ( ctx context . Context ,
rollup_node_id Rollup_NodeId_Field ) (
rows [ ] * Rollup , err error )
Create_Raw ( ctx context . Context ,
raw_node_id Raw_NodeId_Field ,
raw_interval_end_time Raw_IntervalEndTime_Field ,
raw_data_total Raw_DataTotal_Field ,
raw_data_type Raw_DataType_Field ) (
raw * Raw , err error )
Create_Rollup ( ctx context . Context ,
rollup_node_id Rollup_NodeId_Field ,
rollup_start_time Rollup_StartTime_Field ,
rollup_interval Rollup_Interval_Field ,
rollup_data_type Rollup_DataType_Field ) (
rollup * Rollup , err error )
2018-11-09 20:02:28 +00:00
2018-12-05 14:03:23 +00:00
Create_Timestamps ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ,
timestamps_value Timestamps_Value_Field ) (
timestamps * Timestamps , err error )
2018-12-12 21:24:08 +00:00
Delete_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ) (
2018-11-09 20:02:28 +00:00
deleted bool , err error )
2018-12-12 21:24:08 +00:00
Delete_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ) (
2018-11-09 20:02:28 +00:00
deleted bool , err error )
2018-12-05 14:03:23 +00:00
Find_Timestamps_Value_By_Name ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ) (
row * Value_Row , err error )
2018-12-12 21:24:08 +00:00
Get_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ) (
raw * Raw , err error )
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
Get_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ) (
rollup * Rollup , err error )
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
Update_Raw_By_Id ( ctx context . Context ,
raw_id Raw_Id_Field ,
update Raw_Update_Fields ) (
raw * Raw , err error )
2018-11-09 20:02:28 +00:00
2018-12-12 21:24:08 +00:00
Update_Rollup_By_Id ( ctx context . Context ,
rollup_id Rollup_Id_Field ,
update Rollup_Update_Fields ) (
rollup * Rollup , err error )
2018-12-05 14:03:23 +00:00
Update_Timestamps_By_Name ( ctx context . Context ,
timestamps_name Timestamps_Name_Field ,
update Timestamps_Update_Fields ) (
timestamps * Timestamps , err error )
2018-11-09 20:02:28 +00:00
}
type TxMethods interface {
Methods
Rebind ( s string ) string
Commit ( ) error
Rollback ( ) error
}
type txMethods interface {
TxMethods
deleteAll ( ctx context . Context ) ( int64 , error )
makeErr ( err error ) error
}
type DBMethods interface {
Methods
Schema ( ) string
Rebind ( sql string ) string
}
type dbMethods interface {
DBMethods
wrapTx ( tx * sql . Tx ) txMethods
makeErr ( err error ) error
}
func openpostgres ( source string ) ( * sql . DB , error ) {
return sql . Open ( "postgres" , source )
}
var sqlite3DriverName = "sqlite3_" + fmt . Sprint ( time . Now ( ) . UnixNano ( ) )
func init ( ) {
sql . Register ( sqlite3DriverName , & sqlite3 . SQLiteDriver {
ConnectHook : sqlite3SetupConn ,
} )
}
// SQLite3JournalMode controls the journal_mode pragma for all new connections.
// Since it is read without a mutex, it must be changed to the value you want
// before any Open calls.
var SQLite3JournalMode = "WAL"
func sqlite3SetupConn ( conn * sqlite3 . SQLiteConn ) ( err error ) {
_ , err = conn . Exec ( "PRAGMA foreign_keys = ON" , nil )
if err != nil {
return makeErr ( err )
}
_ , err = conn . Exec ( "PRAGMA journal_mode = " + SQLite3JournalMode , nil )
if err != nil {
return makeErr ( err )
}
return nil
}
func opensqlite3 ( source string ) ( * sql . DB , error ) {
return sql . Open ( sqlite3DriverName , source )
}