Skip to content

Commit

Permalink
Tidy the Commands definition
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossEvol committed May 28, 2024
1 parent b5432a1 commit c9d95a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
22 changes: 11 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ to quickly create a Cobra application.`,

var configCmd = &cobra.Command{
Use: "config",
Short: "config",
Short: "This command can generate the sqlcc.toml and then validate it, or it can generate the sqlc.json for sqlc generation.",
Long: ``,
// Uncomment the following line if your bare application
// has an action associated with it:
Expand All @@ -55,7 +55,7 @@ var configCmd = &cobra.Command{

var configInitCmd = &cobra.Command{
Use: "init",
Short: "init",
Short: "Generate the sqlcc.toml config file.",
Args: func(cmd *cobra.Command, args []string) error {
return nil
},
Expand Down Expand Up @@ -87,7 +87,7 @@ LOG_ENABLED = false

var configValidateCmd = &cobra.Command{
Use: "validate",
Short: "validate",
Short: "Validate the sqlcc.toml , whether it can connect to the database or not.",
Long: ``,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
Expand Down Expand Up @@ -127,7 +127,7 @@ var configValidateCmd = &cobra.Command{

var configSqliteCmd = &cobra.Command{
Use: "sqlite",
Short: "sqlite",
Short: "Generate the sqlc.json for sqlite dialect.",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
const sqlite3SqlcJson = `
Expand Down Expand Up @@ -179,7 +179,7 @@ var configSqliteCmd = &cobra.Command{

var configMysqlCmd = &cobra.Command{
Use: "mysql",
Short: "mysql",
Short: "Generate the sqlc.json for mysql dialect.",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
const mysqlSqlcJson = `
Expand Down Expand Up @@ -231,7 +231,7 @@ var configMysqlCmd = &cobra.Command{

var configPgxCmd = &cobra.Command{
Use: "pgx",
Short: "pgx",
Short: "Generate the sqlc.json for postgres dialect.",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
const pgxSqlcJson = `
Expand Down Expand Up @@ -286,9 +286,9 @@ var configPgxCmd = &cobra.Command{
},
}

var genCmd = &cobra.Command{
var genCrudSqlCmd = &cobra.Command{
Use: "gen",
Short: "gen",
Short: "Generate the basic curd sql statement for sqlc",
Long: ``,
Args: func(cmd *cobra.Command, args []string) error {
return nil
Expand All @@ -309,7 +309,7 @@ var genCmd = &cobra.Command{
},
}

var sqlBuilderMapperCmd = &cobra.Command{
var genSqlBuilderMapperCmd = &cobra.Command{
Use: "map",
Short: "map the table metadata to an object.",
Long: `when using the sql builder for golang, use this command to map the column name to static constants by organize them into an object using the column names as values, which can improve the type safety.`,
Expand Down Expand Up @@ -356,8 +356,8 @@ func Execute() {

func init() {
rootCmd.AddCommand(configCmd)
rootCmd.AddCommand(genCmd)
rootCmd.AddCommand(sqlBuilderMapperCmd)
rootCmd.AddCommand(genCrudSqlCmd)
rootCmd.AddCommand(genSqlBuilderMapperCmd)
configCmd.AddCommand(configInitCmd)
configCmd.AddCommand(configValidateCmd)
configCmd.AddCommand(configMysqlCmd)
Expand Down
18 changes: 11 additions & 7 deletions sqlcc.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Choose the dialect among ['postgres', 'mysql', 'sqlite']
DB_DRIVER = "mysql"

# dsn should be in the form of user:password@tcp(host:port)/db?k=v
DB_DSN = "rootomf:7LImSxF1HZ5oBS0WnE@tcp(localhost:3306)/grpc_todo?charset=utf8"
# Choose the dialect among ['pgx', 'mysql', 'sqlite3']
DB_DRIVER = "<?>"

# target database name you choose
DB_NAME = "grpc_todo"
# mysql => user:password@tcp(host:port)/db?k=v
# pgx => user:password@host:port/db?k=v
DB_DSN = "user:password@tcp(host:port)/test_db?charset=utf8"

# target database name you choose , not needed for sqlite and pgx, only for mysql
DB_NAME = "test_db"

# target tables used for stmt generation
TABLES = ["category", "group", "todo", "todo_detail", "todo_tag", "todosongroups"]
TABLES = ["XXXX", "YYYY"]

# Enable logger or not
LOG_ENABLED = false

0 comments on commit c9d95a0

Please sign in to comment.