data/command.go
func ExecuteCommand(args []string) error {
	if len(args) == 0 {
		return nil
	}

	switch args[0] {
	case "db-create":
		f := readFlags(args)
		if err := createDatabase(f.connection); err != nil {
			panic("failed to create database: " + err.Error())
		}
		os.Exit(0)
	case "db-migrate":
		f := readFlags(args)
		err := migration.Migrate(f.connection, f.version)
		if err != nil {
			panic("failed to run migration: " + err.Error())
		}
		os.Exit(0)
	case "db-init-data":
		f := readFlags(args)
		if err := initData(f.connection); err != nil {
			panic("failed to init database: " + err.Error())
		}
		os.Exit(0)
	case "db-version":
		f := readFlags(args)
		version, err := migration.Version(f.connection)
		if err != nil {
			msg := "failed to print database schema version: "
			panic(msg + err.Error())
		}
		fmt.Println("database schema version:", version)
		os.Exit(0)
	}
	return nil
}
func ExecuteCommand(args []string) error {
	if len(args) == 0 {
		return nil
	}

	switch args[0] {
	case "db-create":
		f := readFlags(args)
		if err := createDatabase(f.connection); err != nil {
			panic("failed to create database: " + err.Error())
		}
		os.Exit(0)
	case "db-migrate":
		f := readFlags(args)
		err := migration.Migrate(f.connection, f.version)
		if err != nil {
			panic("failed to run migration: " + err.Error())
		}
		os.Exit(0)
	case "db-init-data":
		f := readFlags(args)
		if err := initData(f.connection); err != nil {
			panic("failed to init database: " + err.Error())
		}
		os.Exit(0)
	case "db-version":
		f := readFlags(args)
		version, err := migration.Version(f.connection)
		if err != nil {
			msg := "failed to print database schema version: "
			panic(msg + err.Error())
		}
		fmt.Println("database schema version:", version)
		os.Exit(0)
	}
	return nil
}
func ExecuteCommand ( args [ ] string ) error { if len ( args ) == 0 { return nil } switch args [ 0 ] { case " " : f := readFlags ( args ) if err := createDatabase ( f . connection ) ; err != nil { panic ( " " + err . Error ( ) ) } os . Exit ( 0 ) case " " : f := readFlags ( args ) err := migration . Migrate ( f . connection , f . version ) if err != nil { panic ( " " + err . Error ( ) ) } os . Exit ( 0 ) case " " : f := readFlags ( args ) if err := initData ( f . connection ) ; err != nil { panic ( " " + err . Error ( ) ) } os . Exit ( 0 ) case " " : f := readFlags ( args ) version , err := migration . Version ( f . connection ) if err != nil { msg := " " panic ( msg + err . Error ( ) ) } fmt . Println ( " " , version ) os . Exit ( 0 ) } return nil }
// ExecuteCommand executes commands to manage database
// db-create - command to create database
// db-migrate - command to execute migration scripts
// db-init-data - command to initialize database by default values
// db-version - command to print the version of the database schema.
ExecuteCommand executes commands to manage database db - create - command to create database db - migrate - command to execute migration scripts db - init - data - command to initialize database by default values db - version - command to print the version of the database schema .