-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34ad57a
commit 2552271
Showing
2 changed files
with
31 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"sync" | ||
|
||
"github.com/charmbracelet/huh" | ||
"github.com/charmbracelet/huh/spinner" | ||
_ "github.com/snowflakedb/gosnowflake" | ||
) | ||
|
||
|
@@ -38,14 +39,14 @@ type SourceTables struct { | |
} | ||
|
||
func main() { | ||
use_form := false | ||
if use_form { | ||
useForm := true | ||
if useForm { | ||
form := huh.NewForm( | ||
huh.NewGroup( | ||
huh.NewNote(). | ||
Title("Welcome to tbd!🏎️✨"). | ||
Description(`A fast and friendly code generator for dbt. | ||
We will generate sources YAML config and SQL staging models for all the tables in the schema you specify. | ||
Title("🏁 Welcome to tbd! 🏎️✨"). | ||
Description(`A sweet and speedy code generator for dbt. | ||
We will generate source YAML config and SQL staging models for all the tables in the schema you specify. | ||
To prepare, make sure you have the following: | ||
✴︎ *_Username_* (e.g. [email protected]) | ||
✴︎ *_Account ID_* (e.g. elfstone-consulting.us-west-1) | ||
|
@@ -98,6 +99,7 @@ For security, we don't currently support password-based authentication.`), | |
confirm = true | ||
} | ||
if confirm { | ||
s := spinner.New() | ||
databaseType := warehouse | ||
if warehouse == "snowflake" { | ||
dbAccount = strings.ToUpper(dbAccount) | ||
|
@@ -106,29 +108,32 @@ For security, we don't currently support password-based authentication.`), | |
dbDatabase = strings.ToUpper(dbDatabase) | ||
} | ||
connStr := fmt.Sprintf("%s@%s/%s/%s?authenticator=externalbrowser", dbUsername, dbAccount, dbDatabase, dbSchema) | ||
ctx, db, err := ConnectToDB(connStr, databaseType) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
s.Action(func() { | ||
ctx, db, err := ConnectToDB(connStr, databaseType) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
tables, err := GetTables(db, ctx) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
tables, err := GetTables(db, ctx) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
PutColumnsOnTables(db, ctx, tables) | ||
CleanBuildDir("build") | ||
PutColumnsOnTables(db, ctx, tables) | ||
CleanBuildDir("build") | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(2) | ||
go func() { | ||
defer wg.Done() | ||
WriteYAML(tables) | ||
}() | ||
go func() { | ||
defer wg.Done() | ||
WriteStagingModels(tables) | ||
}() | ||
wg.Wait() | ||
var wg sync.WaitGroup | ||
wg.Add(2) | ||
go func() { | ||
defer wg.Done() | ||
WriteYAML(tables) | ||
}() | ||
go func() { | ||
defer wg.Done() | ||
WriteStagingModels(tables) | ||
}() | ||
wg.Wait() | ||
}).Title("🏎️✨ Generating YAML and SQL files...").Run() | ||
fmt.Println("🏁 Done! Your YAML and SQL files are in the build directory.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters