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"
|
2017-11-16 20:53:13 +00:00
|
|
|
"strings"
|
2016-09-14 21:23:02 +00:00
|
|
|
"time"
|
2017-11-16 20:53:13 +00:00
|
|
|
|
|
|
|
"golang.org/x/text/language"
|
2016-09-14 21:23:02 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
2017-03-02 14:38:56 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Other
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2017-03-24 21:25:16 +00:00
|
|
|
type AuthableStatement interface {
|
|
|
|
Auth() (string, string)
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:38:56 +00:00
|
|
|
type KillableStatement interface {
|
2017-04-28 16:12:11 +00:00
|
|
|
Duration() time.Duration
|
2017-03-02 14:38:56 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:13 +00:00
|
|
|
type WriteableStatement interface {
|
|
|
|
Writeable() bool
|
2017-03-02 14:38:56 +00:00
|
|
|
}
|
|
|
|
|
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:"-"`
|
2016-11-23 12:53:27 +00:00
|
|
|
Kind Token `cork:"-" codec:"-"`
|
2017-03-02 10:47:10 +00:00
|
|
|
What *Table `cork:"-" codec:"-"`
|
2016-09-19 10:08:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:13 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// If
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// IfStatement represents an if else clause.
|
|
|
|
type IfStatement struct {
|
|
|
|
RW bool `cork:"-" codec:"-"`
|
|
|
|
Cond Exprs `cork:"cond" codec:"cond"`
|
|
|
|
Then Exprs `cork:"then" codec:"then"`
|
|
|
|
Else Expr `cork:"else" codec:"else"`
|
|
|
|
}
|
|
|
|
|
2018-04-14 16:55:05 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Run
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// RunStatement represents a run clause.
|
|
|
|
type RunStatement struct {
|
|
|
|
RW bool `cork:"-" codec:"-"`
|
|
|
|
Expr Expr `cork:"expr" codec:"expr"`
|
|
|
|
}
|
|
|
|
|
2016-10-29 11:28:20 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// LET
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// LetStatement represents a SQL LET statement.
|
|
|
|
type LetStatement struct {
|
2017-11-16 20:53:13 +00:00
|
|
|
RW bool `cork:"-" codec:"-"`
|
2016-11-04 11:15:05 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Name *Ident `cork:"-" codec:"-"`
|
2016-11-04 09:57:17 +00:00
|
|
|
What Expr `cork:"-" codec:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReturnStatement represents a SQL RETURN statement.
|
|
|
|
type ReturnStatement struct {
|
2017-11-16 20:53:13 +00:00
|
|
|
RW bool `cork:"-" codec:"-"`
|
2016-11-04 11:15:05 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2017-11-16 20:53:13 +00:00
|
|
|
What Exprs `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 {
|
2017-11-16 20:53:13 +00:00
|
|
|
ID string `cork:"ID" codec:"ID"`
|
|
|
|
FB string `cork:"FB" codec:"FB"`
|
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
|
|
|
Diff bool `cork:"diff" codec:"diff"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Expr Fields `cork:"expr" codec:"expr"`
|
2017-12-08 10:05:21 +00:00
|
|
|
What Exprs `cork:"what" codec:"what"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
2017-11-16 20:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// KillStatement represents a SQL KILL statement.
|
|
|
|
type KillStatement struct {
|
|
|
|
FB string `cork:"FB" codec:"FB"`
|
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
2017-12-08 10:05:21 +00:00
|
|
|
What Exprs `cork:"what" codec:"what"`
|
2016-10-14 21:21:17 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// SelectStatement represents a SQL SELECT statement.
|
|
|
|
type SelectStatement struct {
|
2017-11-16 20:53:13 +00:00
|
|
|
RW bool `cork:"-" codec:"-"`
|
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
|
|
|
Expr Fields `cork:"expr" codec:"expr"`
|
|
|
|
What Exprs `cork:"what" codec:"what"`
|
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
|
|
|
Group Groups `cork:"group" codec:"group"`
|
|
|
|
Order Orders `cork:"order" codec:"order"`
|
|
|
|
Limit Expr `cork:"limit" codec:"limit"`
|
|
|
|
Start Expr `cork:"start" codec:"start"`
|
|
|
|
Version Expr `cork:"version" codec:"version"`
|
|
|
|
Timeout time.Duration `cork:"timeout" codec:"timeout"`
|
|
|
|
Parallel int `cork:"parallel" codec:"parallel"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateStatement represents a SQL CREATE statement.
|
|
|
|
type CreateStatement struct {
|
2017-11-16 20:53:13 +00:00
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
|
|
|
What Exprs `cork:"what" codec:"what"`
|
|
|
|
Data Expr `cork:"data" codec:"data"`
|
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
|
|
|
Timeout time.Duration `cork:"timeout" codec:"timeout"`
|
|
|
|
Parallel int `cork:"parallel" codec:"parallel"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateStatement represents a SQL UPDATE statement.
|
|
|
|
type UpdateStatement struct {
|
2017-11-16 20:53:13 +00:00
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
|
|
|
What Exprs `cork:"what" codec:"what"`
|
|
|
|
Data Expr `cork:"data" codec:"data"`
|
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
|
|
|
Timeout time.Duration `cork:"timeout" codec:"timeout"`
|
|
|
|
Parallel int `cork:"parallel" codec:"parallel"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteStatement represents a SQL DELETE statement.
|
|
|
|
type DeleteStatement struct {
|
2017-11-16 20:53:13 +00:00
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
|
|
|
Hard bool `cork:"hard" codec:"hard"`
|
|
|
|
What Exprs `cork:"what" codec:"what"`
|
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
|
|
|
Timeout time.Duration `cork:"timeout" codec:"timeout"`
|
|
|
|
Parallel int `cork:"parallel" codec:"parallel"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RelateStatement represents a SQL RELATE statement.
|
|
|
|
type RelateStatement struct {
|
2017-11-16 20:53:13 +00:00
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
|
|
|
Type Expr `cork:"type" codec:"type"`
|
|
|
|
From Exprs `cork:"from" codec:"from"`
|
|
|
|
With Exprs `cork:"with" codec:"with"`
|
|
|
|
Data Expr `cork:"data" codec:"data"`
|
|
|
|
Uniq bool `cork:"uniq" codec:"uniq"`
|
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
|
|
|
Timeout time.Duration `cork:"timeout" codec:"timeout"`
|
|
|
|
Parallel int `cork:"parallel" codec:"parallel"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// InsertStatement represents a SQL INSERT statement.
|
|
|
|
type InsertStatement struct {
|
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
|
|
|
Data Expr `cork:"data" codec:"data"`
|
|
|
|
Into *Table `cork:"into" codec:"into"`
|
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
|
|
|
Timeout time.Duration `cork:"timeout" codec:"timeout"`
|
|
|
|
Parallel int `cork:"parallel" codec:"parallel"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpsertStatement represents a SQL UPSERT statement.
|
|
|
|
type UpsertStatement struct {
|
|
|
|
KV string `cork:"KV" codec:"KV"`
|
|
|
|
NS string `cork:"NS" codec:"NS"`
|
|
|
|
DB string `cork:"DB" codec:"DB"`
|
|
|
|
Data Expr `cork:"data" codec:"data"`
|
|
|
|
Into *Table `cork:"into" codec:"into"`
|
|
|
|
Echo Token `cork:"echo" codec:"echo"`
|
|
|
|
Timeout time.Duration `cork:"timeout" codec:"timeout"`
|
|
|
|
Parallel int `cork:"parallel" codec:"parallel"`
|
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:"-"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
2016-11-04 11:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RemoveNamespaceStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
2016-11-04 11:29:08 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 11:34:37 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Database
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
type DefineDatabaseStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
2016-11-04 11:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RemoveDatabaseStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
2016-11-04 11:34:37 +00:00
|
|
|
}
|
|
|
|
|
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"`
|
2017-03-02 10:47:10 +00:00
|
|
|
User *Ident `cork:"user" codec:"user"`
|
2016-11-22 13:36:57 +00:00
|
|
|
Pass []byte `cork:"pass" codec:"pass"`
|
2016-11-22 13:51:21 +00:00
|
|
|
Code []byte `cork:"code" codec:"code"`
|
2016-11-16 22:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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"`
|
2017-03-02 10:47:10 +00:00
|
|
|
User *Ident `cork:"user" codec:"user"`
|
2016-11-16 22:43:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 22:47:23 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Token
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// DefineTokenStatement represents an SQL DEFINE TOKEN statement.
|
|
|
|
type DefineTokenStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Kind Token `cork:"kind" codec:"kind"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
2016-11-16 22:47:23 +00:00
|
|
|
Type string `cork:"type" codec:"type"`
|
2016-11-22 13:51:21 +00:00
|
|
|
Code []byte `cork:"code" codec:"code"`
|
2016-11-16 22:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveTokenStatement represents an SQL REMOVE TOKEN statement.
|
|
|
|
type RemoveTokenStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Kind Token `cork:"kind" codec:"kind"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
2016-11-16 22:47:23 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 21:21:25 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Scope
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// DefineScopeStatement represents an SQL DEFINE SCOPE statement.
|
|
|
|
type DefineScopeStatement struct {
|
2018-03-18 21:30:02 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
|
|
|
Time time.Duration `cork:"time" codec:"time"`
|
|
|
|
Code []byte `cork:"code" codec:"code"`
|
|
|
|
Signup Expr `cork:"signup" codec:"signup"`
|
|
|
|
Signin Expr `cork:"signin" codec:"signin"`
|
|
|
|
Connect Expr `cork:"connect" codec:"connect"`
|
|
|
|
OnSignup Expr `cork:"onsignup" codec:"onsignup"`
|
|
|
|
OnSignin Expr `cork:"onsignin" codec:"onsignin"`
|
2016-10-14 21:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveScopeStatement represents an SQL REMOVE SCOPE statement.
|
|
|
|
type RemoveScopeStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
2017-03-02 10:47:10 +00:00
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
2016-10-14 21:21:25 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2017-11-16 20:53:13 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
|
|
|
What Tables `cork:"-" codec:"-"`
|
|
|
|
Full bool `cork:"full" codec:"full"`
|
|
|
|
Drop bool `cork:"drop" codec:"drop"`
|
|
|
|
Lock bool `cork:"lock" codec:"lock"`
|
|
|
|
Expr Fields `cork:"expr" codec:"expr"`
|
|
|
|
From Tables `cork:"from" codec:"from"`
|
|
|
|
Cond Expr `cork:"cond" codec:"cond"`
|
|
|
|
Group Groups `cork:"group" codec:"group"`
|
|
|
|
Perms Expr `cork:"perms" codec:"perms"`
|
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 {
|
2017-03-02 10:47:10 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
What Tables `cork:"-" codec:"-"`
|
2016-07-21 21:50:16 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:13 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Event
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// DefineEventStatement represents an SQL DEFINE EVENT statement.
|
|
|
|
type DefineEventStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
|
|
|
What Tables `cork:"-" codec:"-"`
|
|
|
|
When Expr `cork:"when" codec:"when"`
|
|
|
|
Then Expr `cork:"then" codec:"then"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveEventStatement represents an SQL REMOVE EVENT statement.
|
|
|
|
type RemoveEventStatement struct {
|
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name *Ident `cork:"-" codec:"-"`
|
|
|
|
What Tables `cork:"-" codec:"-"`
|
|
|
|
}
|
|
|
|
|
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 {
|
2017-12-05 01:56:33 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
|
|
|
What Tables `cork:"-" codec:"-"`
|
|
|
|
Perms Expr `cork:"perms" codec:"perms"`
|
|
|
|
Type string `cork:"type" codec:"type"`
|
|
|
|
Kind string `cork:"kind" codec:"kind"`
|
|
|
|
Value Expr `cork:"value" codec:"value"`
|
|
|
|
Assert Expr `cork:"assert" codec:"assert"`
|
|
|
|
Priority float64 `cork:"priority" codec:"priority"`
|
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 {
|
2017-03-02 10:47:10 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name *Ident `cork:"-" codec:"-"`
|
|
|
|
What Tables `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 {
|
2017-03-02 10:47:10 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name *Ident `cork:"name" codec:"name"`
|
|
|
|
What Tables `cork:"-" codec:"-"`
|
|
|
|
Cols Idents `cork:"cols" codec:"cols"`
|
|
|
|
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 {
|
2017-03-02 10:47:10 +00:00
|
|
|
KV string `cork:"-" codec:"-"`
|
|
|
|
NS string `cork:"-" codec:"-"`
|
|
|
|
DB string `cork:"-" codec:"-"`
|
|
|
|
Name *Ident `cork:"-" codec:"-"`
|
|
|
|
What Tables `cork:"-" codec:"-"`
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Literals
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Expr represents a sql expression.
|
2016-02-26 17:27:07 +00:00
|
|
|
type Expr interface{}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Exprs represents multiple sql expressions.
|
|
|
|
type Exprs []Expr
|
|
|
|
|
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{}
|
|
|
|
|
2017-12-12 01:09:08 +00:00
|
|
|
// Null represents an expression which is null.
|
|
|
|
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
|
2017-11-16 20:53:13 +00:00
|
|
|
Field string
|
|
|
|
Alias string
|
2016-09-14 21:23:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Fields represents multiple SELECT AS clauses.
|
|
|
|
type Fields []*Field
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
// Group represents a GROUP BY clause.
|
|
|
|
type Group struct {
|
|
|
|
Expr Expr
|
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Groups represents multiple GROUP BY clauses.
|
|
|
|
type Groups []*Group
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
// Order represents a ORDER BY clause.
|
|
|
|
type Order struct {
|
|
|
|
Expr Expr
|
2017-11-16 20:53:13 +00:00
|
|
|
Dir bool
|
|
|
|
Tag language.Tag
|
2016-09-14 21:23:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Orders represents multiple ORDER BY clauses.
|
|
|
|
type Orders []*Order
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-03-18 21:01:29 +00:00
|
|
|
// MultExpression represents multiple queries.
|
|
|
|
type MultExpression struct {
|
|
|
|
Expr []Expr
|
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:13 +00:00
|
|
|
// IfelExpression represents an if else clause.
|
|
|
|
type IfelExpression struct {
|
|
|
|
Cond Exprs
|
|
|
|
Then Exprs
|
|
|
|
Else Expr
|
|
|
|
}
|
|
|
|
|
2016-11-04 09:57:17 +00:00
|
|
|
// FuncExpression represents a function call.
|
|
|
|
type FuncExpression struct {
|
|
|
|
Name string
|
2017-03-02 10:47:10 +00:00
|
|
|
Args Exprs
|
2017-11-16 20:53:13 +00:00
|
|
|
Aggr bool
|
2016-11-04 09:57:17 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// ItemExpression represents a part of a SET expression.
|
|
|
|
type ItemExpression struct {
|
2016-11-04 09:57:17 +00:00
|
|
|
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 {
|
2017-03-02 10:47:10 +00:00
|
|
|
Expr Exprs
|
2016-11-04 09:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PartExpression represents a path part expression.
|
|
|
|
type PartExpression struct {
|
|
|
|
Part Expr
|
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// JoinExpression represents a path join expression.
|
2016-11-04 09:57:17 +00:00
|
|
|
type JoinExpression struct {
|
|
|
|
Join Token
|
|
|
|
}
|
|
|
|
|
|
|
|
// SubpExpression represents a sub path expression.
|
|
|
|
type SubpExpression struct {
|
2017-03-02 10:47:10 +00:00
|
|
|
What Exprs
|
|
|
|
Name *Ident
|
2016-11-04 09:57:17 +00:00
|
|
|
Cond Expr
|
|
|
|
}
|
|
|
|
|
2016-11-26 13:39:03 +00:00
|
|
|
// PermExpression represents a permissions expression.
|
|
|
|
type PermExpression struct {
|
|
|
|
Select Expr
|
|
|
|
Create Expr
|
|
|
|
Update Expr
|
|
|
|
Delete Expr
|
2017-03-02 10:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DataExpression represents a SET expression.
|
|
|
|
type DataExpression struct {
|
|
|
|
Data []*ItemExpression
|
2016-11-26 13:39:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 09:57:17 +00:00
|
|
|
// DiffExpression represents a JSON to DIFF
|
2016-05-23 12:32:02 +00:00
|
|
|
type DiffExpression struct {
|
2017-03-02 10:47:10 +00:00
|
|
|
Data Expr
|
2016-05-23 12:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MergeExpression represents JSON to MERGE
|
|
|
|
type MergeExpression struct {
|
2017-03-02 10:47:10 +00:00
|
|
|
Data Expr
|
2016-05-23 12:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ContentExpression represents JSON to REPLACE
|
|
|
|
type ContentExpression struct {
|
2017-03-02 10:47:10 +00:00
|
|
|
Data Expr
|
2016-05-23 12:32:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-14 12:21:08 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Model
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Model comment
|
|
|
|
type Model struct {
|
|
|
|
TB string
|
|
|
|
MIN float64
|
|
|
|
INC float64
|
|
|
|
MAX float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewModel(TB string, MIN, INC, MAX float64) *Model {
|
|
|
|
return &Model{TB: TB, MIN: MIN, INC: INC, MAX: MAX}
|
|
|
|
}
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// --------------------------------------------------
|
2017-03-02 10:47:10 +00:00
|
|
|
// Param
|
2016-02-26 17:27:07 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Params represents multiple Param clauses.
|
|
|
|
type Params []*Param
|
|
|
|
|
|
|
|
// Param comment
|
|
|
|
type Param struct {
|
2016-09-06 13:30:59 +00:00
|
|
|
ID string
|
2016-07-04 10:37:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
func NewParam(ID string) *Param {
|
|
|
|
return &Param{ID}
|
2016-09-14 21:23:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
2017-03-02 10:47:10 +00:00
|
|
|
// Value
|
2016-09-14 21:23:02 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Values represents multiple Value clauses.
|
|
|
|
type Values []*Value
|
|
|
|
|
|
|
|
// Value comment
|
|
|
|
type Value struct {
|
2016-10-29 11:28:20 +00:00
|
|
|
ID string
|
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
func NewValue(ID string) *Value {
|
|
|
|
return &Value{ID}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Ident
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Idents represents multiple Ident clauses.
|
|
|
|
type Idents []*Ident
|
|
|
|
|
|
|
|
// Ident comment
|
|
|
|
type Ident struct {
|
|
|
|
ID string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIdent(ID string) *Ident {
|
|
|
|
return &Ident{ID}
|
2016-10-29 11:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
2017-03-02 10:47:10 +00:00
|
|
|
// Table
|
2016-10-29 11:28:20 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Tables represents multiple Table clauses.
|
|
|
|
type Tables []*Table
|
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2017-11-16 20:53:13 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Batch
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Batchs represents multiple Batch clauses.
|
|
|
|
type Batchs []*Batch
|
|
|
|
|
|
|
|
// Batch comment
|
|
|
|
type Batch struct {
|
|
|
|
TB string
|
|
|
|
BA []*Thing
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewBatch(TB string, BA []interface{}) *Batch {
|
|
|
|
var b = &Batch{TB: TB}
|
|
|
|
for _, ID := range BA {
|
|
|
|
b.BA = append(b.BA, NewThing(TB, ID))
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2016-09-14 21:23:02 +00:00
|
|
|
// --------------------------------------------------
|
2017-03-02 10:47:10 +00:00
|
|
|
// Thing
|
2016-09-14 21:23:02 +00:00
|
|
|
// --------------------------------------------------
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
// Things represents multiple Thing clauses.
|
|
|
|
type Things []*Thing
|
|
|
|
|
2016-02-26 17:27:07 +00:00
|
|
|
// Thing comment
|
|
|
|
type Thing struct {
|
2017-03-02 10:47:10 +00:00
|
|
|
TB string
|
2016-05-24 12:51:52 +00:00
|
|
|
ID interface{}
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 13:17:50 +00:00
|
|
|
func ParseThing(val string) *Thing {
|
|
|
|
r := strings.NewReader(val)
|
|
|
|
s := newScanner(r)
|
|
|
|
if t, _, v := s.scanThing(); t == THING {
|
|
|
|
return v.(*Thing)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-02 10:47:10 +00:00
|
|
|
func NewThing(TB string, ID interface{}) *Thing {
|
2017-11-16 20:53:13 +00:00
|
|
|
switch val := ID.(type) {
|
|
|
|
default:
|
|
|
|
return &Thing{TB: TB, ID: ID}
|
|
|
|
case int:
|
|
|
|
return &Thing{TB: TB, ID: float64(val)}
|
|
|
|
case int64:
|
|
|
|
return &Thing{TB: TB, ID: float64(val)}
|
|
|
|
case string:
|
|
|
|
val = strings.Replace(val, TB+":", "", -1)
|
|
|
|
if cnv, err := strconv.ParseFloat(val, 64); err == nil {
|
2016-09-14 21:23:02 +00:00
|
|
|
return &Thing{TB: TB, ID: cnv}
|
2017-11-16 20:53:13 +00:00
|
|
|
} else if cnv, err := strconv.ParseBool(val); err == nil {
|
2017-04-14 12:13:31 +00:00
|
|
|
return &Thing{TB: TB, ID: cnv}
|
2017-11-16 20:53:13 +00:00
|
|
|
} else if cnv, err := time.Parse(RFCDate, val); err == nil {
|
2016-09-14 21:23:02 +00:00
|
|
|
return &Thing{TB: TB, ID: cnv.UTC()}
|
2017-11-16 20:53:13 +00:00
|
|
|
} else if cnv, err := time.Parse(RFCTime, val); err == nil {
|
2016-09-14 21:23:02 +00:00
|
|
|
return &Thing{TB: TB, ID: cnv.UTC()}
|
|
|
|
}
|
2017-11-16 20:53:13 +00:00
|
|
|
return &Thing{TB: TB, ID: val}
|
2016-09-14 21:23:02 +00:00
|
|
|
}
|
2017-11-16 20:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Point
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Points represents multiple Point clauses.
|
|
|
|
type Points []*Point
|
|
|
|
|
|
|
|
// Point comment
|
|
|
|
type Point struct {
|
|
|
|
LA float64
|
|
|
|
LO float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPoint(LA, LO float64) *Point {
|
|
|
|
return &Point{LA: LA, LO: LO}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Circle
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Circles represents multiple Circle clauses.
|
|
|
|
type Circles []*Circle
|
|
|
|
|
|
|
|
// Circle comment
|
|
|
|
type Circle struct {
|
|
|
|
CE *Point
|
|
|
|
RA float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCircle(CE *Point, RA float64) *Circle {
|
|
|
|
return &Circle{CE: CE, RA: RA}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Polygon
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
// Polygons represents multiple Polygon clauses.
|
|
|
|
type Polygons []*Polygon
|
|
|
|
|
|
|
|
// Polygon comment
|
|
|
|
type Polygon struct {
|
|
|
|
PS Points
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPolygon(PS ...*Point) *Polygon {
|
|
|
|
return &Polygon{PS: PS}
|
2016-02-26 17:27:07 +00:00
|
|
|
}
|