Skip to content
Snippets Groups Projects
Commit 70699ed5 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Small fix for the basic add

parent b39b3aa7
Branches
No related tags found
No related merge requests found
Pipeline #82657 canceled
...@@ -32,7 +32,15 @@ ds init ...@@ -32,7 +32,15 @@ ds init
### Add a new table ### Add a new table
```bash ```bash
ds add table "Table Name" ds add
```
```bash
ds add "Table Name"
```
```bash
ds add users --model '{"fields":[{"name":"id","type":"INT","primary_key":true,"auto_increment":true,"not_null":true},{"name":"name","type":"VARCHAR(255)","unique":true,"not_null":true},{"name":"email","type":"VARCHAR(255)","unique":true,"not_null":true},{"name":"created_at","type":"DATETIME","not_null":true,"default_value":"CURRENT_TIMESTAMP"}]}'
``` ```
## Contributing ## Contributing
......
...@@ -299,18 +299,18 @@ func promptForTableModel() TableModel { ...@@ -299,18 +299,18 @@ func promptForTableModel() TableModel {
utils.PromptIfEmpty(&field.Name, "Enter field name: ") utils.PromptIfEmpty(&field.Name, "Enter field name: ")
field.Type = promptForFieldType() field.Type = promptForFieldType()
field.PrimaryKey = utils.PromptForBool("Is this a primary key? (y/n): ") field.PrimaryKey = utils.PromptForBool("Is this a primary key? (y/n): ") // TODO: use SelectMenu
if !field.PrimaryKey { if !field.PrimaryKey {
utils.PromptIfEmpty(&field.ForeignKey, "Enter foreign key (leave empty if not applicable): ") utils.PromptIfEmpty(&field.ForeignKey, "Enter foreign key (leave empty if not applicable): ")
} }
field.Unique = utils.PromptForBool("Is this field unique? (y/n): ") field.Unique = utils.PromptForBool("Is this field unique? (y/n): ") // TODO: use SelectMenu
field.NotNull = utils.PromptForBool("Is this field not null? (y/n): ") field.NotNull = utils.PromptForBool("Is this field not null? (y/n): ") // TODO: use SelectMenu
field.AutoIncrement = utils.PromptForBool("Is this field auto-increment? (y/n): ") field.AutoIncrement = utils.PromptForBool("Is this field auto-increment? (y/n): ") // TODO: use SelectMenu
field.DefaultValue = utils.PromptForString("Enter default value (leave empty if not applicable): ") field.DefaultValue = utils.PromptForString("Enter default value (leave empty if not applicable): ")
fields = append(fields, field) fields = append(fields, field)
if !utils.PromptForBool("Do you want to add another field? (y/n): ") { if !utils.PromptForBool("Do you want to add another field? (y/n): ") { // TODO: use SelectMenu
break break
} }
} }
......
...@@ -36,13 +36,19 @@ func main() { ...@@ -36,13 +36,19 @@ func main() {
case "add": case "add":
var tableName, model string var tableName, model string
args := os.Args[2:] args := os.Args[2:]
for i, arg := range args { for i := 0; i < len(args); i++ {
arg := args[i]
if arg == "--model" && i+1 < len(args) { if arg == "--model" && i+1 < len(args) {
model = args[i+1] model = args[i+1]
i++ // Skip the next argument since it's the model value
} else if !strings.HasPrefix(arg, "--") { } else if !strings.HasPrefix(arg, "--") {
tableName = arg tableName = arg
} }
} }
if tableName == "" {
fmt.Println("Usage: ds add <tablename> [--model <json_model>]")
return
}
commands.Add(tableName, model) commands.Add(tableName, model)
case "version": case "version":
commands.Version(version) commands.Version(version)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment