2016-02-26 17:27:07 +00:00
|
|
|
// Copyright © 2016 Abcum Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package sql
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Queries
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Query represents a multi statement SQL query
|
|
|
|
type Query struct {
|
|
|
|
Statements Statements
|
|
|
|
}
|
|
|
|
|
|
|
|
// Statement represents a single SQL AST
|
|
|
|
type Statement interface{}
|
|
|
|
|
|
|
|
// Statements represents multiple SQL ASTs
|
|
|
|
type Statements []Statement
|
|
|
|
|
2016-05-23 12:32:02 +00:00
|
|
|
// --------------------------------------------------
|
2016-09-06 13:30:59 +00:00
|
|
|
// Trans
|
2016-05-23 12:32:02 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
// UseStatement represents a SQL BEGIN TRANSACTION statement.
|
2016-09-06 13:30:59 +00:00
|
|
|
type BeginStatement struct{}
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
// UseStatement represents a SQL CANCEL TRANSACTION statement.
|
2016-09-06 13:30:59 +00:00
|
|
|
type CancelStatement struct{}
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
// UseStatement represents a SQL COMMIT TRANSACTION statement.
|
2016-09-06 13:30:59 +00:00
|
|
|
type CommitStatement struct{}
|
|
|
|
|
2016-09-19 10:08:44 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Use
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// UseStatement represents a SQL USE statement.
|
|
|
|
type UseStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2016-09-19 10:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Info
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// InfoStatement represents an SQL INFO statement.
|
|
|
|
type InfoStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
What string `cork:"-" codec:"-"`
|
2016-09-19 10:08:44 +00:00
|
|
|
}
|
|
|
|
|
2016-10-29 11:28:20 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// LET
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// LetStatement represents a SQL LET statement.
|
|
|
|
type LetStatement struct {
|
2016-11-04 11:15:05 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2016-10-29 11:28:20 +00:00
|
|
|
Name string `cork:"-" codec:"-"`
|
2016-11-04 09:57:17 +00:00
|
|
|
What Expr `cork:"-" codec:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReturnStatement represents a SQL RETURN statement.
|
|
|
|
type ReturnStatement struct {
|
2016-11-04 11:15:05 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
What Expr `cork:"-" codec:"-"`
|
2016-10-29 11:28:20 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 13:30:59 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Normal
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-10-14 21:21:17 +00:00
|
|
|
// LiveStatement represents a SQL LIVE statement.
|
|
|
|
type LiveStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Expr []*Field `cork:"expr" codec:"expr"`
|
|
|
|
What []Expr `cork:"what" codec:"what"`
|
2016-11-04 09:57:17 +00:00
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
2016-10-14 21:21:17 +00:00
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
|
|
|
}
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// SelectStatement represents a SQL SELECT statement.
|
|
|
|
type SelectStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Expr []*Field `cork:"expr" codec:"expr"`
|
|
|
|
What []Expr `cork:"what" codec:"what"`
|
2016-11-04 09:57:17 +00:00
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
2016-10-01 23:17:19 +00:00
|
|
|
Group []*Group `cork:"group" codec:"group"`
|
|
|
|
Order []*Order `cork:"order" codec:"order"`
|
|
|
|
Limit Expr `cork:"limit" codec:"limit"`
|
|
|
|
Start Expr `cork:"start" codec:"start"`
|
|
|
|
Version Expr `cork:"version" codec:"version"`
|
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateStatement represents a SQL CREATE statement.
|
|
|
|
type CreateStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
What []Expr `cork:"what" codec:"what"`
|
|
|
|
Data []Expr `cork:"data" codec:"data"`
|
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateStatement represents a SQL UPDATE statement.
|
|
|
|
type UpdateStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2016-11-04 11:43:59 +00:00
|
|
|
Hard bool `cork:"hard" codec:"hard"`
|
2016-10-01 23:17:19 +00:00
|
|
|
What []Expr `cork:"what" codec:"what"`
|
|
|
|
Data []Expr `cork:"data" codec:"data"`
|
2016-11-04 09:57:17 +00:00
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
2016-10-01 23:17:19 +00:00
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteStatement represents a SQL DELETE statement.
|
|
|
|
type DeleteStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Hard bool `cork:"hard" codec:"hard"`
|
|
|
|
What []Expr `cork:"what" codec:"what"`
|
2016-11-04 09:57:17 +00:00
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
2016-10-01 23:17:19 +00:00
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RelateStatement represents a SQL RELATE statement.
|
|
|
|
type RelateStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2016-11-04 09:57:17 +00:00
|
|
|
Type Expr `cork:"type" codec:"type"`
|
2016-10-01 23:17:19 +00:00
|
|
|
From []Expr `cork:"from" codec:"from"`
|
2016-11-04 09:57:17 +00:00
|
|
|
With []Expr `cork:"with" codec:"with"`
|
2016-10-01 23:17:19 +00:00
|
|
|
Data []Expr `cork:"data" codec:"data"`
|
2016-11-04 09:57:17 +00:00
|
|
|
Uniq bool `cork:"uniq" codec:"uniq"`
|
2016-10-01 23:17:19 +00:00
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 11:29:08 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Namespace
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
type DefineNamespaceStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RemoveNamespaceStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
}
|
|
|
|
|
2016-11-04 11:34:37 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Database
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
type DefineDatabaseStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RemoveDatabaseStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
}
|
|
|
|
|
2016-11-16 22:43:36 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Login
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// DefineLoginStatement represents an SQL DEFINE LOGIN statement.
|
|
|
|
type DefineLoginStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Kind Token `cork:"kind" codec:"kind"`
|
|
|
|
User string `cork:"user" codec:"user"`
|
|
|
|
Pass string `cork:"pass" codec:"pass"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveLoginStatement represents an SQL REMOVE LOGIN statement.
|
|
|
|
type RemoveLoginStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Kind Token `cork:"kind" codec:"kind"`
|
|
|
|
User string `cork:"user" codec:"user"`
|
|
|
|
}
|
|
|
|
|
2016-10-14 21:21:25 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Scope
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// DefineScopeStatement represents an SQL DEFINE SCOPE statement.
|
|
|
|
type DefineScopeStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
Time time.Duration `cork:"time" codec:"time"`
|
|
|
|
Opts interface{} `cork:"opts" codec:"opts"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveScopeStatement represents an SQL REMOVE SCOPE statement.
|
|
|
|
type RemoveScopeStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
}
|
|
|
|
|
2016-07-21 21:50:16 +00:00
|
|
|
// --------------------------------------------------
|
2016-09-20 23:25:39 +00:00
|
|
|
// Table
|
2016-07-21 21:50:16 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-09-20 23:25:39 +00:00
|
|
|
// DefineTableStatement represents an SQL DEFINE TABLE statement.
|
|
|
|
type DefineTableStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
What []string `cork:"-" codec:"-"`
|
2016-10-14 20:31:45 +00:00
|
|
|
Full bool `cork:"full" codec:"full"`
|
2016-07-21 21:50:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-20 23:25:39 +00:00
|
|
|
// RemoveTableStatement represents an SQL REMOVE TABLE statement.
|
|
|
|
type RemoveTableStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
What []string `cork:"-" codec:"-"`
|
2016-07-21 21:50:16 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// --------------------------------------------------
|
2016-09-20 23:25:39 +00:00
|
|
|
// Rules
|
2016-02-26 17:27:07 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-09-20 23:25:39 +00:00
|
|
|
// DefineRulesStatement represents an SQL DEFINE RULES statement.
|
|
|
|
type DefineRulesStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
What []string `cork:"-" codec:"-"`
|
|
|
|
When []string `cork:"-" codec:"-"`
|
|
|
|
Rule string `cork:"rule" codec:"rule"`
|
2016-11-04 09:57:17 +00:00
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
2016-09-20 23:25:39 +00:00
|
|
|
// RemoveRulesStatement represents an SQL REMOVE RULES statement.
|
|
|
|
type RemoveRulesStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
What []string `cork:"-" codec:"-"`
|
|
|
|
When []string `cork:"-" codec:"-"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 12:32:02 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Field
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-09-20 23:25:39 +00:00
|
|
|
// DefineFieldStatement represents an SQL DEFINE FIELD statement.
|
2016-05-23 12:32:02 +00:00
|
|
|
type DefineFieldStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
What []string `cork:"-" codec:"-"`
|
|
|
|
Type string `cork:"type" codec:"type"`
|
|
|
|
Enum []interface{} `cork:"enum" codec:"enum"`
|
|
|
|
Code string `cork:"code" codec:"code"`
|
|
|
|
Min float64 `cork:"min" codec:"min"`
|
|
|
|
Max float64 `cork:"max" codec:"max"`
|
|
|
|
Match string `cork:"match" codec:"match"`
|
|
|
|
Default interface{} `cork:"default" codec:"default"`
|
|
|
|
Notnull bool `cork:"notnull" codec:"notnull"`
|
|
|
|
Readonly bool `cork:"readonly" codec:"readonly"`
|
|
|
|
Mandatory bool `cork:"mandatory" codec:"mandatory"`
|
|
|
|
Validate bool `cork:"validate" codec:"validate"`
|
2016-05-23 12:32:02 +00:00
|
|
|
}
|
|
|
|
|
2016-09-20 23:25:39 +00:00
|
|
|
// RemoveFieldStatement represents an SQL REMOVE FIELD statement.
|
2016-05-23 12:32:02 +00:00
|
|
|
type RemoveFieldStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"-" codec:"-"`
|
|
|
|
What []string `cork:"-" codec:"-"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
2016-05-23 12:32:02 +00:00
|
|
|
// Index
|
2016-02-26 17:27:07 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-05-23 12:32:02 +00:00
|
|
|
// DefineIndexStatement represents an SQL DEFINE INDEX statement.
|
|
|
|
type DefineIndexStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
What []string `cork:"-" codec:"-"`
|
|
|
|
Cols []string `cork:"cols" codec:"cols"`
|
2016-10-14 21:52:57 +00:00
|
|
|
Uniq bool `cork:"uniq" codec:"uniq"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 12:32:02 +00:00
|
|
|
// RemoveIndexStatement represents an SQL REMOVE INDEX statement.
|
|
|
|
type RemoveIndexStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"-" codec:"-"`
|
|
|
|
What []string `cork:"-" codec:"-"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
2016-09-20 23:36:37 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// View
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// DefineViewStatement represents an SQL DEFINE VIEW statement.
|
|
|
|
type DefineViewStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"name" codec:"name"`
|
|
|
|
Expr []*Field `cork:"expr" codec:"expr"`
|
|
|
|
What []Expr `cork:"what" codec:"what"`
|
2016-11-04 09:57:17 +00:00
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
2016-10-01 23:17:19 +00:00
|
|
|
Group []*Group `cork:"group" codec:"group"`
|
2016-09-20 23:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveViewStatement represents an SQL REMOVE VIEW statement.
|
|
|
|
type RemoveViewStatement struct {
|
2016-10-01 23:17:19 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name string `cork:"-" codec:"-"`
|
2016-09-20 23:36:37 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Literals
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Expr represents a sql expression
|
|
|
|
type Expr interface{}
|
|
|
|
|
2016-11-04 09:57:17 +00:00
|
|
|
// All represents a * expression.
|
2016-07-04 10:37:37 +00:00
|
|
|
type All struct{}
|
|
|
|
|
2016-11-04 09:57:17 +00:00
|
|
|
// Any represents a ? expression.
|
|
|
|
type Any struct{}
|
|
|
|
|
2016-05-23 12:32:02 +00:00
|
|
|
// Asc represents the ASC expression.
|
|
|
|
type Asc struct{}
|
|
|
|
|
|
|
|
// Desc represents the DESC expression.
|
|
|
|
type Desc struct{}
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// Null represents a null expression.
|
|
|
|
type Null struct{}
|
|
|
|
|
2016-05-23 12:32:02 +00:00
|
|
|
// Void represents an expression which is not set.
|
|
|
|
type Void struct{}
|
|
|
|
|
|
|
|
// Empty represents an expression which is null or "".
|
|
|
|
type Empty struct{}
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
// Field represents a SELECT AS clause.
|
|
|
|
type Field struct {
|
|
|
|
Expr Expr
|
|
|
|
Alias string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Group represents a GROUP BY clause.
|
|
|
|
type Group struct {
|
|
|
|
Expr Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
// Order represents a ORDER BY clause.
|
|
|
|
type Order struct {
|
|
|
|
Expr Expr
|
|
|
|
Dir Expr
|
|
|
|
}
|
|
|
|
|
2016-11-04 09:57:17 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Expressions
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// SubExpression represents a subquery.
|
|
|
|
type SubExpression struct {
|
2016-02-26 17:27:07 +00:00
|
|
|
Expr Expr
|
|
|
|
}
|
|
|
|
|
2016-11-04 09:57:17 +00:00
|
|
|
// FuncExpression represents a function call.
|
|
|
|
type FuncExpression struct {
|
|
|
|
Name string
|
|
|
|
Args []Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
// DataExpression represents a SET expression.
|
|
|
|
type DataExpression struct {
|
|
|
|
LHS Expr
|
|
|
|
Op Token
|
|
|
|
RHS Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
// BinaryExpression represents a WHERE expression.
|
2016-02-26 17:27:07 +00:00
|
|
|
type BinaryExpression struct {
|
|
|
|
LHS Expr
|
2016-09-06 13:30:59 +00:00
|
|
|
Op Token
|
2016-02-26 17:27:07 +00:00
|
|
|
RHS Expr
|
|
|
|
}
|
|
|
|
|
2016-11-04 09:57:17 +00:00
|
|
|
// PathExpression represents a path expression.
|
|
|
|
type PathExpression struct {
|
|
|
|
Expr []Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
// PartExpression represents a path part expression.
|
|
|
|
type PartExpression struct {
|
|
|
|
Part Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
// PartExpression represents a path join expression.
|
|
|
|
type JoinExpression struct {
|
|
|
|
Join Token
|
|
|
|
}
|
|
|
|
|
|
|
|
// SubpExpression represents a sub path expression.
|
|
|
|
type SubpExpression struct {
|
|
|
|
What []Expr
|
|
|
|
Name string
|
|
|
|
Cond Expr
|
|
|
|
}
|
|
|
|
|
|
|
|
// DiffExpression represents a JSON to DIFF
|
2016-05-23 12:32:02 +00:00
|
|
|
type DiffExpression struct {
|
2016-07-04 10:37:37 +00:00
|
|
|
JSON interface{}
|
2016-05-23 12:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MergeExpression represents JSON to MERGE
|
|
|
|
type MergeExpression struct {
|
2016-07-04 10:37:37 +00:00
|
|
|
JSON interface{}
|
2016-05-23 12:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ContentExpression represents JSON to REPLACE
|
|
|
|
type ContentExpression struct {
|
2016-07-04 10:37:37 +00:00
|
|
|
JSON interface{}
|
2016-05-23 12:32:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Parts
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-09-06 13:30:59 +00:00
|
|
|
// Ident comment
|
|
|
|
type Ident struct {
|
|
|
|
ID string
|
2016-07-04 10:37:37 +00:00
|
|
|
}
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
func NewIdent(ID string) *Ident {
|
|
|
|
return &Ident{ID}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Parts
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-10-29 11:28:20 +00:00
|
|
|
// Param comment
|
|
|
|
type Param struct {
|
|
|
|
ID string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewParam(ID string) *Param {
|
|
|
|
return &Param{ID}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Parts
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-09-06 13:30:59 +00:00
|
|
|
// Table comment
|
|
|
|
type Table struct {
|
|
|
|
TB string
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
func NewTable(TB string) *Table {
|
|
|
|
return &Table{TB}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Parts
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// Thing comment
|
|
|
|
type Thing struct {
|
2016-10-29 10:38:52 +00:00
|
|
|
TB interface{}
|
2016-05-24 12:51:52 +00:00
|
|
|
ID interface{}
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-29 10:38:52 +00:00
|
|
|
func NewThing(TB interface{}, ID interface{}) *Thing {
|
2016-09-14 21:23:02 +00:00
|
|
|
if str, ok := ID.(string); ok {
|
2016-10-29 09:20:10 +00:00
|
|
|
if cnv, err := strconv.ParseFloat(str, 64); err == nil {
|
|
|
|
if cnv == float64(int64(cnv)) {
|
|
|
|
return &Thing{TB: TB, ID: int64(cnv)}
|
|
|
|
}
|
2016-09-14 21:23:02 +00:00
|
|
|
return &Thing{TB: TB, ID: cnv}
|
|
|
|
} else if cnv, err := time.Parse(RFCDate, str); err == nil {
|
|
|
|
return &Thing{TB: TB, ID: cnv.UTC()}
|
|
|
|
} else if cnv, err := time.Parse(RFCTime, str); err == nil {
|
|
|
|
return &Thing{TB: TB, ID: cnv.UTC()}
|
|
|
|
} else if cnv, err := time.Parse(RFCNorm, str); err == nil {
|
|
|
|
return &Thing{TB: TB, ID: cnv.UTC()}
|
|
|
|
} else if cnv, err := time.Parse(RFCText, str); err == nil {
|
|
|
|
return &Thing{TB: TB, ID: cnv.UTC()}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &Thing{TB: TB, ID: ID}
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|