Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConfigFile string
The filepath to the config file which will be used by ParseFile to load the configuration. If not provided ParseFile will look for a config file in the caller's git project root.
NOTE This value is set by the ParseFlags method.
var DefaultConfig = Config{ WorkingDirectory: String{Value: "."}, Recursive: Bool{Value: false}, InputFiles: StringSlice{}, InputFileRegexps: StringSlice{}, OutputFileNameFormat: String{Value: "%s_gosql.go"}, DatabaseDSN: String{Value: ""}, QuoteIdentifiers: Bool{Value: false}, FilterColumnKeyTag: String{Value: "json"}, FilterColumnKeyBase: Bool{Value: false}, FilterColumnKeySeparator: String{Value: "."}, MethodName: String{Value: "Exec"}, MethodWithContext: Bool{Value: false}, MethodArgumentType: GoType{ Name: "Conn", PkgPath: "github.com/frk/gosql", PkgName: "gosql", }, }
Functions ¶
This section is empty.
Types ¶
type Bool ¶
Bool implements both the flag.Value and the json.Unmarshal interfaces enforcing priority of flags over json, meaning that json.Unmarshal will not override the value if it was previously set by flag.Var.
func (Bool) IsBoolFlag ¶
IsBoolFlag indicates that the Bool type can be used as a boolean flag.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Config ¶
type Config struct { // The directory in which the tool will search for files to process. // If not provided, the current working directory will be used by default. WorkingDirectory String `json:"working_directory"` // If set to true, the tool will search the hierarchy of the working // directory for files to process. Recursive Bool `json:"recursive"` // List of files to be used as input for the tool. // The files must be located in the working directory. InputFiles StringSlice `json:"input_files"` // List of regular expressions to match input files that the tool should // process. The regular expressions must match files that are located in // the working directory. InputFileRegexps StringSlice `json:"input_file_regexps"` // The format used for generating the name of the output files. // // The format can contain one (and only one) "%s" placeholder which the // tool will replace with the input file's base name, if no placeholder is // present then the input file's base name will be prefixed to the format. // // If not provided, the format "%s_gosql.go" will be used by default. OutputFileNameFormat String `json:"output_file_name_format"` // The connection string of the database that will be used for type checking. // This value is required. DatabaseDSN String `json:"database_dsn"` // If set to true, the generator will quote postgres identifiers like // column names, table names, etc. QuoteIdentifiers Bool `json:"quote_identifiers"` // If set to a non-empty string, it specifies the struct tag to be used // for constructing the column keys of a FilterXxx type. A valid tag must // begin with a letter (A-z) or an underscore (_), subsequent characters // in the tag can be letters, underscores, and digits (0-9). // If set to "" (empty string), the generator will default to use the // field names instead of struct tags to construct the column keys. // // If not provided, the tag "json" will be used by default. FilterColumnKeyTag String `json:"filter_column_key_tag"` // If set, instructs the generator to use only the base of a tag/field // chain to construct the column keys of a FilterXxx type. // // If not provided, `false` will be used by default. FilterColumnKeyBase Bool `json:"filter_column_key_base"` // The separator to be used to join a chain of tag/field values for // constructing the column keys of a FilterXxx type. The separator can // be at most one byte long. // // If not provided, the separator "." will be used by default. FilterColumnKeySeparator String `json:"filter_column_key_separator"` // The name to be used for the generated method. // // If not provided, the name "Exec" will be used by default. MethodName String `json:"method_name"` // If set, the generator will produce methods that take context.Context // as its first argument and they will pass that argument to the XxxContext // query executing methods of the Conn type. // // If not provided, `false` will be used by default. MethodWithContext Bool `json:"method_with_context"` // The Go type to be used as the "querier" argument for the generated methods. // // The string value must be of the format "[*]package/path.TypeName" and // the type represented by it must implement the following interface: // { // Exec(query string, args ...interface{}) (sql.Result, error) // ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) // Query(query string, args ...interface{}) (*sql.Rows, error) // QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) // QueryRow(query string, args ...interface{}) *sql.Row // QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row // } // // If not provided, the type github.com/frk/gosql.Conn will be used by default. MethodArgumentType GoType `json:"method_argument_type"` // contains filtered or unexported fields }
The Config struct is used to configure the gosql tool.
func (*Config) FileFilterFunc ¶
func (*Config) ParseFile ¶
ParseFile looks for a gosql config file in the git project's root of the receiver's working directory, if it finds such a file it will then unmarshal it into the receiver.
func (*Config) ParseFlags ¶
func (c *Config) ParseFlags(printUsage func())
ParseFlags unmarshals the cli flags into the receiver.
type GoType ¶
GoType implements both the flag.Value and the json.Unmarshal interfaces enforcing priority of flags over json, meaning that json.Unmarshal will not override the value if it was previously set by flag.Var.
func (*GoType) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type String ¶
String implements both the flag.Value and the json.Unmarshal interfaces enforcing priority of flags over json, meaning that json.Unmarshal will not override the value if it was previously set by flag.Var.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type StringSlice ¶
StringSlice implements both the flag.Value and the json.Unmarshal interfaces enforcing priority of flags over json, meaning that json.Unmarshal will not override the value if it was previously set by flag.Var.
func (StringSlice) Get ¶
func (ss StringSlice) Get() interface{}
Get implements the flag.Getter interface.
func (*StringSlice) Set ¶
func (ss *StringSlice) Set(value string) error
Set implements the flag.Value interface.
func (StringSlice) String ¶
func (ss StringSlice) String() string
String implements the flag.Value interface.
func (*StringSlice) UnmarshalJSON ¶
func (ss *StringSlice) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.