cmd

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: Apache-2.0 Imports: 49 Imported by: 0

README

Command line datly executor

./datly -h
Generate rule with endpoint for a table
 ./datly  -C=dev  -N=MyViewName -T=MyTableName
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
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(args []string, logger io.Writer) *standalone.Server

Types

type Column added in v0.2.1

type Column struct {
	Ns     string
	Name   string
	Alias  string
	Except []string
}

type Columns added in v0.2.1

type Columns []*Column

func (Columns) ByAlias added in v0.2.1

func (c Columns) ByAlias() map[string]*Column

func (Columns) ByNs added in v0.2.1

func (c Columns) ByNs(ns string) map[string]*Column

func (Columns) StarExpr added in v0.2.1

func (c Columns) StarExpr(ns string) *Column

type Connector

type Connector struct {
	DbName string `short:"C" 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) New

func (c *Connector) New() *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 Generate

type Generate struct {
	Name         string   `short:"N" long:"name" description:"view DbName/route URI" `
	Table        string   `short:"T" long:"table" description:"table" `
	SQLLocation  string   `short:"S" long:"sql" description:"SQL location" `
	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" `
}

func (*Generate) Namespace

func (g *Generate) Namespace() string

type Join added in v0.2.1

type Join struct {
	Key      string
	KeyAlias string
	OwnerKey string
	OwnerNs  string
	Owner    *Table
	Field    string

	ToOne bool
	Table *Table
}

type Joins added in v0.2.1

type Joins []*Join

func (*Joins) Index added in v0.2.1

func (j *Joins) Index() map[string]*Join

type Options

type Options struct {
	Port          int    `short:"p" long:"port" description:"port"  `
	RouteURL      string `short:"r" long:"mode" description:"route URL"  `
	DependencyURL string `short:"d" long:"deps" description:"dependencies URL" `
	ConfigURL     string `short:"c" long:"config" description:"configuration URL" `
	WriteLocation string `short:"w" long:"write" description:"dump all config files to specified location" `
	Generate
	Connector
	Content
	OpenApiURL string `short:"o" long:"openapi"`
}

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() string

func (*Options) RouterURL

func (o *Options) RouterURL() string

func (*Options) SQLURL added in v0.2.1

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

type Table added in v0.2.1

type Table struct {
	Ref         string
	StarExpr    bool
	Inner       Columns
	ColumnTypes map[string]string
	InnerAlias  string
	InnerSQL    string
	Columns     Columns
	Name        string
	SQL         string
	Joins       Joins
	Alias       string

	ViewMeta *ast.ViewMeta
}

func ParseSQLx added in v0.2.1

func ParseSQLx(SQL string) (*Table, error)

Directories

Path Synopsis
ast

Jump to

Keyboard shortcuts

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