cmd

package
v0.2.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 50 Imported by: 0

README

Command line datly executor

./datly -h
Generate rule with endpoint for a table
 ./datly -C='mydb|mysql|root:pass@tcp(127.0.0.1:3306)/mydb?parseTime=true'  -N=MyViewName -T=MyTableName
 
open http://127.0.0.1:8080/v1/api/dev/MyViewName

Generate rule with endpoint for a table and SQL
 ./datly  -C=dev  -N=MyViewName -T=MyTableName -S=view.sql
 ./datly  -C=dev  -N=MyViewName -T=MyTableName
Generate rule with endpoint for a table and relations
 ./datly  -C=dev  -N=MyViewName -T=MyTableName  -R=MyRelName:RelTable 
SQLx (extension) based rule generation
One to many

rule.sql

SELECT 
    dept.*
    employee.*
FROM DEPARMENT dept
JOIN EMP employee ON dept.ID = employee.DEPT_ID 
datly -N=dept -X=rule.sql
One to one relation

rule.sql

SELECT 
    dept.*
    employee.*,
    organization.*
FROM DEPARMENT dept
JOIN EMP employee ON dept.ID = employee.DEPT_ID
JOIN ORG organization ON organization.ID = demp.ORG_ID AND 1=1
datly -N=dept -X=rule.sql
Excluding output column

rule.sql

SELECT 
    dept.* EXCEPT ORG_ID
    employee.* EXCEPT DEPT_ID, 
    organization.* 
FROM DEPARMENT dept
JOIN EMP employee ON dept.ID = employee.DEPT_ID
JOIN ORG organization ON organization.ID = demp.ORG_ID AND 1=1
datly -N=dept -X=rule.sql
View SQL

rule.sql

SELECT 
    dept.* EXCEPT ORG_ID
    employee.* EXCEPT DEPT_ID, 
    organization.* 
FROM (SELECT * FROM DEPARMENT t) dept
JOIN (SELECT ID, NAME, DEPT_ID FROM EMP t) employee ON dept.ID = employee.DEPT_ID
JOIN ORG organization ON organization.ID = demp.ORG_ID AND 1=1
datly -N=dept -X=rule.sql
View SQL with velty template and query parameters
SELECT 
    dept.* EXCEPT ORG_ID
    employee.* EXCEPT DEPT_ID, 
    organization.* 
FROM (SELECT * FROM DEPARMENT t) dept
JOIN (SELECT ID, NAME, DEPT_ID FROM EMP t) employee ON dept.ID = employee.DEPT_ID
JOIN ORG organization ON organization.ID = demp.ORG_ID AND 1=1
WHERE 1=1
#if ($Has.Id)
AND ID = $Id
#end
View SQL with query parameters
SELECT 
    dept.* EXCEPT ORG_ID
    employee.* EXCEPT DEPT_ID, 
    organization.* 
FROM (SELECT * FROM DEPARMENT t) dept
JOIN (SELECT ID, NAME, DEPT_ID FROM EMP t) employee ON dept.ID = employee.DEPT_ID
JOIN ORG organization ON organization.ID = demp.ORG_ID AND 1=1
WHERE ID = $Id
View SQL column type codec
SELECT 
    dept.* EXCEPT ORG_ID
    employee.* EXCEPT DEPT_ID, 
    organization.* 
FROM (SELECT * FROM DEPARMENT t) dept
JOIN (SELECT ID, NAME, DEPT_ID, 
    (CASE WHEN COLUMN_X = 1 THEN
            'x1,x2'
             WHEN COLUMN_X = 2 THEN
            'x3,x4'
       END) AS SLICE /* {"Codec":{"Ref":"AsStrings"}, "DataType": "string"} */  
    FROM EMP t) employee ON dept.ID = employee.DEPT_ID
JOIN ORG organization ON organization.ID = demp.ORG_ID AND 1=1
WHERE ID = $Id
Supported conversion Codecs
- AsStrings: converts coma separated value into []string
Setting matching URI
/* {"URI":"dept/"} */
SELECT
dept.* EXCEPT ORG_ID
employee.* EXCEPT DEPT_ID
FROM (SELECT * FROM DEPARMENT t) dept               
JOIN (SELECT ID, NAME, DEPT_ID FROM EMP t) employee 
 ON dept.ID = employee.DEPT_ID
Setting data caching
/* {"URI":"dept/", 
   "Cache":{
         "Name": "fs"
         "Location": "/tmp/cache/${view.Name}",
         "TimeToLiveMs": 360000
         }
   } */
SELECT
dept.* EXCEPT ORG_ID
employee.* EXCEPT DEPT_ID
FROM (SELECT * FROM DEPARMENT t) dept                /* {"Cache":{"Ref":"fs"}} */
JOIN (SELECT ID, NAME, DEPT_ID FROM EMP t) employee  /* {"Cache":{"Ref":"fsgit p"}} */
 ON dept.ID = employee.DEPT_ID
/* {"URI":"dept/", 
   "Cache":{
         "Name": "aerospike",
         "Provider": "aerospike://127.0.0.1:3000/test",
         "Location": "${view.Name}",
         "TimeToLiveMs": 360000
         }
   } */
SELECT
dept.* EXCEPT ORG_ID
employee.* EXCEPT DEPT_ID
FROM (SELECT * FROM DEPARMENT t) dept                /* {"Cache":{"Ref":"aerospike"}} */
JOIN (SELECT ID, NAME, DEPT_ID FROM EMP t) employee  /* {"Cache":{"Ref":"aerospike"}} */
 ON dept.ID = employee.DEPT_ID

Setting selector

SELECT
dept.* EXCEPT ORG_ID
employee.* EXCEPT DEPT_ID
FROM (SELECT * FROM DEPARMENT t) dept                /* {"Selector":{"Limit": 40, "Constraints"{"Criteria": false}}} */
JOIN (SELECT ID, NAME, DEPT_ID FROM EMP t) employee  /* {"Selector":{"Limit": 80, "Constraints"{"Criteria": false, "Limit": false, "Offset": false}}} */
 ON dept.ID = employee.DEPT_ID
Persisting routes/config to the local folder

Use -w=location switch

datly -N=dept -T=DEPT -w=my_project

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TimeNow = time.Now

Functions

func New added in v0.2.2

func New(version string, args []string, logger io.Writer) (*standalone.Server, error)

func ParseSQLx added in v0.2.1

func ParseSQLx(SQL string, routeOpt *option.Route, hints option.ParameterHints) (*option.Table, map[string]*option.TableParam, error)

func UpdateAuthToken added in v0.2.11

func UpdateAuthToken(aTable *option.Table)

func UpdateTableSettings added in v0.2.11

func UpdateTableSettings(table *option.Table, routeOpt *option.Route, hints option.ParameterHints) error

Types

type CacheWarmup added in v0.2.11

type CacheWarmup struct {
	WarmupURIs []string `short:"u" long:"wuri" description:"uri to warmup cache" `
}

type Connector

type Connector struct {
	Connects []string `short:"C" long:"conn" description:"name|driver|dsn" `
	DbName   string   `short:"V" long:"dbname" description:"db/connector name" `
	Driver   string   `short:"D" long:"driver" description:"driver" `
	DSN      string   `short:"A" long:"dsn" description:"DSN" `
	Secret   string   `short:"E" long:"secret" description:"database secret" `
}

func (*Connector) Init

func (c *Connector) Init()

func (*Connector) MatchConnector added in v0.2.5

func (c *Connector) MatchConnector(name string) *view.Connector

MatchConnector returns matcher or default connector

func (*Connector) New

func (c *Connector) New() *view.Connector

func (*Connector) Registry added in v0.2.5

func (c *Connector) Registry() map[string]*view.Connector

type Content added in v0.2.1

type Content struct {
	Output         string `short:"O" long:"output" description:"output style" choice:"c" choice:"b" `
	RedirectSizeKb int    `short:"M" long:"redirect" description:"redirectMinSize" `
	RedirectURL    string `short:"L" long:"redirectURL" description:"redirectURL" `
}

type DataTyped added in v0.2.11

type DataTyped struct {
	DataType string
}

type Generate

type Generate struct {
	Name         string   `short:"N" long:"name" description:"view DbName/route URI" `
	Table        string   `short:"T" long:"table" description:"table" `
	SQLXLocation string   `short:"X" long:"sqlx" description:"SQLX (extension for relation) location" `
	Relations    []string `short:"R" long:"relation" description:"relation in form of viewName:tableName" ` //TODO: remove
}

func (*Generate) Namespace

func (g *Generate) Namespace() string

type Options

type Options struct {
	Port          int    `short:"p" long:"port" description:"port"  `
	RouteURL      string `short:"r" long:"route URL" description:"route URL"  `
	DependencyURL string `short:"d" long:"deps" description:"dependencies URL" `
	ConfigURL     string `short:"c" long:"config" description:"configuration URL" `
	JWTVerifier   string `short:"j" long:"jwt" description:"PublicKeyPath|EncKey" `
	WriteLocation string `short:"w" long:"write" description:"dump all config files to specified location" `
	Generate
	Connector
	Content
	CacheWarmup
	OpenApiURL string `short:"o" long:"openapi"`
	Version    bool   `short:"v" long:"version"  description:"build version" `
}

func (*Options) DepURL added in v0.2.1

func (o *Options) DepURL(uri string) string

func (*Options) Init

func (o *Options) Init()

func (*Options) ResponseField added in v0.2.1

func (c *Options) ResponseField() string

func (*Options) RouterURI

func (o *Options) RouterURI(name string) string

func (*Options) RouterURL

func (o *Options) RouterURL() string

func (*Options) SQLURL added in v0.2.1

func (o *Options) SQLURL(name string, addSubFolder bool) string

Directories

Path Synopsis
ast

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL