From 9e8fd4912a5d93ac31244777a986b578f7fb8ac6 Mon Sep 17 00:00:00 2001 From: Jorge Rojas Date: Sun, 8 Sep 2024 12:29:43 -0400 Subject: [PATCH] chore: converts magic strings into constants --- components/ConnectionForm.go | 14 +++---- components/ConnectionPage.go | 4 +- components/ConnectionSelection.go | 18 ++++----- components/Home.go | 20 +++++----- components/Pages.go | 2 +- components/ResultTableFilter.go | 2 +- components/ResultsTable.go | 48 +++++++++++------------ components/ResultsTableMenu.go | 16 ++++---- components/SQLEditor.go | 4 +- components/Sidebar.go | 10 ++--- components/Tree.go | 6 +-- components/constants.go | 63 ++++++++++++++++++++++++++++++- drivers/constants.go | 7 ++++ drivers/mysql.go | 2 +- drivers/postgres.go | 2 +- drivers/sqlite.go | 2 +- 16 files changed, 143 insertions(+), 77 deletions(-) diff --git a/components/ConnectionForm.go b/components/ConnectionForm.go index 36d6c26..127769c 100644 --- a/components/ConnectionForm.go +++ b/components/ConnectionForm.go @@ -77,7 +77,7 @@ func NewConnectionForm(connectionPages *models.ConnectionPages) *ConnectionForm func (form *ConnectionForm) inputCapture(connectionPages *models.ConnectionPages) func(event *tcell.EventKey) *tcell.EventKey { return func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyEsc { - connectionPages.SwitchToPage("Connections") + connectionPages.SwitchToPage(ConnectionsPageName) } else if event.Key() == tcell.KeyF1 || event.Key() == tcell.KeyEnter { connectionName := form.GetFormItem(0).(*tview.InputField).GetText() @@ -111,7 +111,7 @@ func (form *ConnectionForm) inputCapture(connectionPages *models.ConnectionPages } switch form.Action { - case "create": + case NewConnection: newDatabases = append(databases, parsedDatabaseData) err := helpers.SaveConnectionConfig(newDatabases) @@ -120,7 +120,7 @@ func (form *ConnectionForm) inputCapture(connectionPages *models.ConnectionPages return event } - case "edit": + case EditConnection: newDatabases = make([]models.Connection, len(databases)) row, _ := ConnectionListTable.GetSelection() @@ -151,7 +151,7 @@ func (form *ConnectionForm) inputCapture(connectionPages *models.ConnectionPages } ConnectionListTable.SetConnections(newDatabases) - connectionPages.SwitchToPage("Connections") + connectionPages.SwitchToPage(ConnectionsPageName) } else if event.Key() == tcell.KeyF2 { connectionString := form.GetFormItem(1).(*tview.InputField).GetText() @@ -173,11 +173,11 @@ func (form *ConnectionForm) testConnection(connectionString string) { var db drivers.Driver switch parsed.Driver { - case "mysql": + case drivers.MySQLDriver: db = &drivers.MySQL{} - case "postgres": + case drivers.PostgresDriver: db = &drivers.Postgres{} - case "sqlite3": + case drivers.SQLiteDriver: db = &drivers.SQLite{} } diff --git a/components/ConnectionPage.go b/components/ConnectionPage.go index 1e13431..aca3c33 100644 --- a/components/ConnectionPage.go +++ b/components/ConnectionPage.go @@ -32,8 +32,8 @@ func NewConnectionPages() *models.ConnectionPages { connectionForm := NewConnectionForm(cp) connectionSelection := NewConnectionSelection(connectionForm, cp) - cp.AddPage("Connections", connectionSelection.Flex, true, true) - cp.AddPage("ConnectionForm", connectionForm.Flex, true, false) + cp.AddPage(ConnectionsSelectionPageName, connectionSelection.Flex, true, true) + cp.AddPage(ConnectionsFormPageName, connectionForm.Flex, true, false) return cp } diff --git a/components/ConnectionSelection.go b/components/ConnectionSelection.go index 53f34d0..6c9232b 100644 --- a/components/ConnectionSelection.go +++ b/components/ConnectionSelection.go @@ -88,18 +88,18 @@ func NewConnectionSelection(connectionForm *ConnectionForm, connectionPages *mod case commands.Connect: go cs.Connect(selectedConnection) case commands.EditConnection: - connectionPages.SwitchToPage("ConnectionForm") + connectionPages.SwitchToPage(ConnectionsFormPageName) connectionForm.GetFormItemByLabel("Name").(*tview.InputField).SetText(selectedConnection.Name) connectionForm.GetFormItemByLabel("URL").(*tview.InputField).SetText(selectedConnection.URL) connectionForm.StatusText.SetText("") - connectionForm.SetAction("edit") + connectionForm.SetAction(EditConnection) return nil case commands.DeleteConnection: confirmationModal := NewConfirmationModal("") confirmationModal.SetDoneFunc(func(_ int, buttonLabel string) { - MainPages.RemovePage("Confirmation") + MainPages.RemovePage(ConfirmationPageName) confirmationModal = nil if buttonLabel == "Yes" { @@ -115,7 +115,7 @@ func NewConnectionSelection(connectionForm *ConnectionForm, connectionPages *mod } }) - MainPages.AddPage("Confirmation", confirmationModal, true, true) + MainPages.AddPage(ConfirmationPageName, confirmationModal, true, true) return nil } @@ -123,11 +123,11 @@ func NewConnectionSelection(connectionForm *ConnectionForm, connectionPages *mod switch command { case commands.NewConnection: - connectionForm.SetAction("create") + connectionForm.SetAction(NewConnection) connectionForm.GetFormItemByLabel("Name").(*tview.InputField).SetText("") connectionForm.GetFormItemByLabel("URL").(*tview.InputField).SetText("") connectionForm.StatusText.SetText("") - connectionPages.SwitchToPage("ConnectionForm") + connectionPages.SwitchToPage(ConnectionsFormPageName) case commands.Quit: if wrapper.HasFocus() { app.App.Stop() @@ -151,11 +151,11 @@ func (cs *ConnectionSelection) Connect(connection models.Connection) { var newDbDriver drivers.Driver switch connection.Provider { - case "mysql": + case drivers.MySQLDriver: newDbDriver = &drivers.MySQL{} - case "postgres": + case drivers.PostgresDriver: newDbDriver = &drivers.Postgres{} - case "sqlite3": + case drivers.SQLiteDriver: newDbDriver = &drivers.SQLite{} } diff --git a/components/Home.go b/components/Home.go index cdca7a5..1226b98 100644 --- a/components/Home.go +++ b/components/Home.go @@ -66,7 +66,7 @@ func NewHomePage(connection models.Connection, dbdriver drivers.Driver) *Home { home.SetInputCapture(home.homeInputCapture) home.SetFocusFunc(func() { - if home.FocusedWrapper == "left" || home.FocusedWrapper == "" { + if home.FocusedWrapper == FocusedWrapperLeft || home.FocusedWrapper == "" { home.focusLeftWrapper() } else { home.focusRightWrapper() @@ -82,7 +82,7 @@ func (home *Home) subscribeToTreeChanges() { for stateChange := range ch { switch stateChange.Key { - case "SelectedTable": + case SelectedTableTree: databaseName := home.Tree.GetSelectedDatabase() tableName := stateChange.Value.(string) @@ -117,7 +117,7 @@ func (home *Home) subscribeToTreeChanges() { } app.App.ForceDraw() - case "IsFiltering": + case IsFilteringTree: isFiltering := stateChange.Value.(bool) if isFiltering { home.SetInputCapture(nil) @@ -140,7 +140,7 @@ func (home *Home) focusRightWrapper() { home.focusTab(tab) } - home.FocusedWrapper = "right" + home.FocusedWrapper = FocusedWrapperRight } func (home *Home) focusTab(tab *Tab) { @@ -193,7 +193,7 @@ func (home *Home) focusLeftWrapper() { App.SetFocus(home.Tree) - home.FocusedWrapper = "left" + home.FocusedWrapper = FocusedWrapperLeft } func (home *Home) rightWrapperInputCapture(event *tcell.EventKey) *tcell.EventKey { @@ -272,11 +272,11 @@ func (home *Home) homeInputCapture(event *tcell.EventKey) *tcell.EventKey { switch command { case commands.MoveLeft: - if table != nil && !table.GetIsEditing() && !table.GetIsFiltering() && home.FocusedWrapper == "right" { + if table != nil && !table.GetIsEditing() && !table.GetIsFiltering() && home.FocusedWrapper == FocusedWrapperRight { home.focusLeftWrapper() } case commands.MoveRight: - if table != nil && !table.GetIsEditing() && !table.GetIsFiltering() && home.FocusedWrapper == "left" { + if table != nil && !table.GetIsEditing() && !table.GetIsFiltering() && home.FocusedWrapper == FocusedWrapperLeft { home.focusRightWrapper() } case commands.SwitchToEditorView: @@ -295,7 +295,7 @@ func (home *Home) homeInputCapture(event *tcell.EventKey) *tcell.EventKey { App.ForceDraw() case commands.SwitchToConnectionsView: if (table != nil && !table.GetIsEditing() && !table.GetIsFiltering() && !table.GetIsLoading()) || table == nil { - MainPages.SwitchToPage("Connections") + MainPages.SwitchToPage(ConnectionsPageName) } case commands.Quit: if tab != nil { @@ -312,7 +312,7 @@ func (home *Home) homeInputCapture(event *tcell.EventKey) *tcell.EventKey { confirmationModal := NewConfirmationModal("") confirmationModal.SetDoneFunc(func(_ int, buttonLabel string) { - MainPages.RemovePage("Confirmation") + MainPages.RemovePage(ConfirmationPageName) confirmationModal = nil if buttonLabel == "Yes" { @@ -332,7 +332,7 @@ func (home *Home) homeInputCapture(event *tcell.EventKey) *tcell.EventKey { } }) - MainPages.AddPage("Confirmation", confirmationModal, true, true) + MainPages.AddPage(ConfirmationPageName, confirmationModal, true, true) } case commands.HelpPopup: if table == nil || !table.GetIsEditing() { diff --git a/components/Pages.go b/components/Pages.go index 257cf76..2055685 100644 --- a/components/Pages.go +++ b/components/Pages.go @@ -8,5 +8,5 @@ var MainPages = tview.NewPages() func init() { MainPages.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor) - MainPages.AddPage("Connections", NewConnectionPages().Flex, true, true) + MainPages.AddPage(ConnectionsPageName, NewConnectionPages().Flex, true, true) } diff --git a/components/ResultTableFilter.go b/components/ResultTableFilter.go index bf526d5..f9e8bf5 100644 --- a/components/ResultTableFilter.go +++ b/components/ResultTableFilter.go @@ -67,7 +67,7 @@ func (filter *ResultsTableFilter) Subscribe() chan models.StateChange { func (filter *ResultsTableFilter) Publish(message string) { for _, sub := range filter.subscribers { sub <- models.StateChange{ - Key: "Filter", + Key: FilteringResultsTable, Value: message, } } diff --git a/components/ResultsTable.go b/components/ResultsTable.go index ebf04af..c547518 100644 --- a/components/ResultsTable.go +++ b/components/ResultsTable.go @@ -89,9 +89,9 @@ func NewResultsTable(listOfDbChanges *[]models.DbDmlChange, tree *Tree, dbdriver loadingModal.SetTextColor(tview.Styles.SecondaryTextColor) pages := tview.NewPages() - pages.AddPage("table", wrapper, true, true) - pages.AddPage("error", errorModal, true, false) - pages.AddPage("loading", loadingModal, false, false) + pages.AddPage(TablePageName, wrapper, true, true) + pages.AddPage(TableErrorPageName, errorModal, true, false) + pages.AddPage(TableLoadingPageName, loadingModal, false, false) pagination := NewPagination() @@ -176,8 +176,8 @@ func (table *ResultsTable) WithEditor() *ResultsTable { resultsInfoText.SetTextColor(tview.Styles.PrimaryTextColor) resultsInfoWrapper.AddItem(resultsInfoText, 3, 0, false) - editorPages.AddPage("Table", tableWrapper, true, false) - editorPages.AddPage("ResultsInfo", resultsInfoWrapper, true, true) + editorPages.AddPage(TableEditorTablePageName, tableWrapper, true, false) + editorPages.AddPage(TableEditorResultsInfoPageName, resultsInfoWrapper, true, true) table.EditorPages = editorPages table.ResultsInfo = resultsInfoText @@ -193,7 +193,7 @@ func (table *ResultsTable) subscribeToTreeChanges() { ch := table.Tree.Subscribe() for stateChange := range ch { - if stateChange.Key == "SelectedDatabase" { + if stateChange.Key == SelectedDatabaseTree { table.SetDatabaseName(stateChange.Value.(string)) } } @@ -204,13 +204,13 @@ func (table *ResultsTable) subscribeToSidebarChanges() { for stateChange := range ch { switch stateChange.Key { - case "Editing": + case EditingSidebar: editing := stateChange.Value.(bool) table.SetIsEditing(editing) - case "Unfocusing": + case UnfocusingSidebar: App.SetFocus(table) App.ForceDraw() - case "Toggling": + case TogglingSidebar: table.ShowSidebar(false) App.ForceDraw() } @@ -493,7 +493,7 @@ func (table *ResultsTable) subscribeToFilterChanges() { for stateChange := range ch { switch stateChange.Key { - case "Filter": + case FilteringResultsTable: if stateChange.Value != "" { rows := table.FetchRecords(nil) @@ -532,7 +532,7 @@ func (table *ResultsTable) subscribeToEditorChanges() { for stateChange := range ch { switch stateChange.Key { - case "Query": + case QuerySQLEditor: query := stateChange.Value.(string) if query != "" { queryLower := strings.ToLower(query) @@ -568,7 +568,7 @@ func (table *ResultsTable) subscribeToEditorChanges() { } table.SetLoading(false) } - table.EditorPages.SwitchToPage("Table") + table.EditorPages.SwitchToPage(TablePageName) App.Draw() } else { table.SetRecords([][]string{}) @@ -584,13 +584,13 @@ func (table *ResultsTable) subscribeToEditorChanges() { } else { table.SetResultsInfo(result) table.SetLoading(false) - table.EditorPages.SwitchToPage("ResultsInfo") + table.EditorPages.SwitchToPage(TableEditorResultsInfoPageName) App.SetFocus(table.Editor) App.Draw() } } } - case "Escape": + case EscapeSQLEditor: table.SetIsFiltering(false) App.SetFocus(table) table.HighlightTable() @@ -704,7 +704,7 @@ func (table *ResultsTable) SetError(err string, done func()) { table.Error.SetText(err) table.Error.SetDoneFunc(func(_ int, _ string) { table.state.error = "" - table.Page.HidePage("error") + table.Page.HidePage(TableErrorPageName) if table.GetIsFiltering() { if table.Editor != nil { App.SetFocus(table.Editor) @@ -718,7 +718,7 @@ func (table *ResultsTable) SetError(err string, done func()) { done() } }) - table.Page.ShowPage("error") + table.Page.ShowPage(TableErrorPageName) App.SetFocus(table.Error) App.ForceDraw() } @@ -731,7 +731,7 @@ func (table *ResultsTable) SetLoading(show bool) { defer func() { if r := recover(); r != nil { logger.Error("ResultsTable.go:800 => Recovered from panic", map[string]any{"error": r}) - _ = table.Page.HidePage("loading") + _ = table.Page.HidePage(TableLoadingPageName) if table.state.error != "" { App.SetFocus(table.Error) } else { @@ -742,11 +742,11 @@ func (table *ResultsTable) SetLoading(show bool) { table.state.isLoading = show if show { - table.Page.ShowPage("loading") + table.Page.ShowPage(TableLoadingPageName) App.SetFocus(table.Loading) App.ForceDraw() } else { - table.Page.HidePage("loading") + table.Page.HidePage(TableLoadingPageName) if table.state.error != "" { App.SetFocus(table.Error) } else { @@ -909,7 +909,7 @@ func (table *ResultsTable) StartEditingCell(row int, col int, callback func(newV if key == tcell.KeyEnter || key == tcell.KeyEscape { table.SetInputCapture(table.tableInputCapture) - table.Page.RemovePage("edit") + table.Page.RemovePage(TableEditCellPageName) App.SetFocus(table) } @@ -920,7 +920,7 @@ func (table *ResultsTable) StartEditingCell(row int, col int, callback func(newV x, y, width := cell.GetLastPosition() inputField.SetRect(x, y, width+1, 1) - table.Page.AddPage("edit", inputField, false, true) + table.Page.AddPage(TableEditCellPageName, inputField, false, true) App.SetFocus(inputField) } @@ -1038,7 +1038,7 @@ func (table *ResultsTable) GetPrimaryKeyValue(rowIndex int) (string, string) { primaryKeyValue := "" switch provider { - case "mysql": + case drivers.MySQLDriver: keyColumnIndex := -1 primaryKeyColumnIndex := -1 @@ -1059,7 +1059,7 @@ func (table *ResultsTable) GetPrimaryKeyValue(rowIndex int) (string, string) { primaryKeyValue = table.GetRecords()[rowIndex][primaryKeyColumnIndex] } - case "postgres": + case drivers.PostgresDriver: keyColumnIndex := -1 constraintTypeColumnIndex := -1 constraintNameColumnIndex := -1 @@ -1101,7 +1101,7 @@ func (table *ResultsTable) GetPrimaryKeyValue(rowIndex int) (string, string) { primaryKeyValue = table.GetRecords()[rowIndex][primaryKeyColumnIndex] } - case "sqlite3": + case drivers.SQLiteDriver: keyColumnIndex := -1 primaryKeyColumnIndex := -1 diff --git a/components/ResultsTableMenu.go b/components/ResultsTableMenu.go index c907fca..858d270 100644 --- a/components/ResultsTableMenu.go +++ b/components/ResultsTableMenu.go @@ -17,11 +17,11 @@ type ResultsTableMenu struct { } var menuItems = []string{ - "Records", - "Columns", - "Constraints", - "Foreign Keys", - "Indexes", + RecordsMenu, + ColumnsMenu, + ConstraintsMenu, + ForeignKeysMenu, + IndexesMenu, } func NewResultsTableMenu() *ResultsTableMenu { @@ -52,11 +52,11 @@ func NewResultsTableMenu() *ResultsTableMenu { size := 15 switch item { - case "Constraints": + case ConstraintsMenu: size = 19 - case "Foreign Keys": + case ForeignKeysMenu: size = 20 - case "Indexes": + case IndexesMenu: size = 16 } diff --git a/components/SQLEditor.go b/components/SQLEditor.go index b3e4389..dc18426 100644 --- a/components/SQLEditor.go +++ b/components/SQLEditor.go @@ -38,10 +38,10 @@ func NewSQLEditor() *SQLEditor { command := app.Keymaps.Group(app.EditorGroup).Resolve(event) if command == commands.Execute { - sqlEditor.Publish("Query", sqlEditor.GetText()) + sqlEditor.Publish(QuerySQLEditor, sqlEditor.GetText()) return nil } else if command == commands.UnfocusEditor { - sqlEditor.Publish("Escape", "") + sqlEditor.Publish(EscapeSQLEditor, "") } else if command == commands.OpenInExternalEditor && runtime.GOOS == "linux" { // ----- THIS IS A LINUX-ONLY FEATURE, for now diff --git a/components/Sidebar.go b/components/Sidebar.go index 91edd66..2fe5ebb 100644 --- a/components/Sidebar.go +++ b/components/Sidebar.go @@ -140,9 +140,9 @@ func (sidebar *Sidebar) inputCapture(event *tcell.EventKey) *tcell.EventKey { switch command { case commands.UnfocusSidebar: - sidebar.Publish(models.StateChange{Key: "Unfocusing", Value: nil}) + sidebar.Publish(models.StateChange{Key: UnfocusingSidebar, Value: nil}) case commands.ToggleSidebar: - sidebar.Publish(models.StateChange{Key: "Toggling", Value: nil}) + sidebar.Publish(models.StateChange{Key: TogglingSidebar, Value: nil}) case commands.MoveDown: sidebar.FocusNextField() case commands.MoveUp: @@ -152,7 +152,7 @@ func (sidebar *Sidebar) inputCapture(event *tcell.EventKey) *tcell.EventKey { case commands.GotoEnd: sidebar.FocusLastField() case commands.Edit: - sidebar.Publish(models.StateChange{Key: "Editing", Value: true}) + sidebar.Publish(models.StateChange{Key: EditingSidebar, Value: true}) currentItemIndex := sidebar.GetCurrentFieldIndex() item := sidebar.Fields[currentItemIndex] @@ -165,13 +165,13 @@ func (sidebar *Sidebar) inputCapture(event *tcell.EventKey) *tcell.EventKey { case commands.CommitEdit: sidebar.SetInputCapture(sidebar.inputCapture) sidebar.SetDisabledStyles(item) - sidebar.Publish(models.StateChange{Key: "Editing", Value: false}) + sidebar.Publish(models.StateChange{Key: EditingSidebar, Value: false}) return nil case commands.DiscardEdit: sidebar.SetInputCapture(sidebar.inputCapture) sidebar.SetDisabledStyles(item) item.SetText(text, true) - sidebar.Publish(models.StateChange{Key: "Editing", Value: false}) + sidebar.Publish(models.StateChange{Key: EditingSidebar, Value: false}) return nil } diff --git a/components/Tree.go b/components/Tree.go index 8d1e743..0c5148e 100644 --- a/components/Tree.go +++ b/components/Tree.go @@ -388,7 +388,7 @@ func (tree *Tree) GetIsFiltering() bool { func (tree *Tree) SetSelectedDatabase(database string) { tree.state.selectedDatabase = database tree.Publish(models.StateChange{ - Key: "SelectedDatabase", + Key: SelectedDatabaseTree, Value: database, }) } @@ -396,7 +396,7 @@ func (tree *Tree) SetSelectedDatabase(database string) { func (tree *Tree) SetSelectedTable(table string) { tree.state.selectedTable = table tree.Publish(models.StateChange{ - Key: "SelectedTable", + Key: SelectedTableTree, Value: table, }) } @@ -404,7 +404,7 @@ func (tree *Tree) SetSelectedTable(table string) { func (tree *Tree) SetIsFiltering(isFiltering bool) { tree.state.isFiltering = isFiltering tree.Publish(models.StateChange{ - Key: "IsFiltering", + Key: IsFilteringTree, Value: isFiltering, }) } diff --git a/components/constants.go b/components/constants.go index 101f2f2..334ca8b 100644 --- a/components/constants.go +++ b/components/constants.go @@ -4,8 +4,67 @@ import "github.com/jorgerojas26/lazysql/app" var App = app.App +// Pages const ( - EditorTabName string = "Editor" - HelpPageName string = "Help" + // General + HelpPageName string = "Help" + ConfirmationPageName string = "Confirmation" + ConnectionsPageName string = "Connections" + + // Results table + TablePageName string = "Table" + TableErrorPageName string = "TableError" + TableLoadingPageName string = "TableLoading" + TableEditorTablePageName string = "TableEditorTable" + TableEditorResultsInfoPageName string = "TableEditorResultsInfo" + TableEditCellPageName string = "TableEditCell" + + // Sidebar SidebarPageName string = "Sidebar" + + // Connections + ConnectionsSelectionPageName string = "ConnectionsSelection" + ConnectionsFormPageName string = "ConnectionsForm" +) + +// Tabs +const ( + EditorTabName string = "Editor" +) + +// Events +const ( + EditingSidebar string = "EditingSidebar" + UnfocusingSidebar string = "UnfocusingSidebar" + TogglingSidebar string = "TogglingSidebar" + + QuerySQLEditor string = "Query" + EscapeSQLEditor string = "Escape" + + FilteringResultsTable string = "FilteringResultsTable" + + SelectedDatabaseTree string = "SelectedDatabase" + SelectedTableTree string = "SelectedTable" + IsFilteringTree string = "IsFiltering" +) + +// Results table menu items +const ( + RecordsMenu string = "Records" + ColumnsMenu string = "Columns" + ConstraintsMenu string = "Constraints" + ForeignKeysMenu string = "Foreign Keys" + IndexesMenu string = "Indexes" +) + +// Actions +const ( + NewConnection string = "NewConnection" + EditConnection string = "EditConnection" +) + +// Misc (until i find a better name) +const ( + FocusedWrapperLeft string = "left" + FocusedWrapperRight string = "right" ) diff --git a/drivers/constants.go b/drivers/constants.go index 5f46aaa..86c7691 100644 --- a/drivers/constants.go +++ b/drivers/constants.go @@ -3,3 +3,10 @@ package drivers const ( DefaultRowLimit = 300 ) + +// Drivers +const ( + MySQLDriver string = "mysql" + PostgresDriver string = "postgres" + SQLiteDriver string = "sqlite3" +) diff --git a/drivers/mysql.go b/drivers/mysql.go index 1c47412..1b27bdd 100644 --- a/drivers/mysql.go +++ b/drivers/mysql.go @@ -22,7 +22,7 @@ func (db *MySQL) TestConnection(urlstr string) (err error) { } func (db *MySQL) Connect(urlstr string) (err error) { - db.SetProvider("mysql") + db.SetProvider(MySQLDriver) db.Connection, err = dburl.Open(urlstr) if err != nil { diff --git a/drivers/postgres.go b/drivers/postgres.go index a3fede9..609492f 100644 --- a/drivers/postgres.go +++ b/drivers/postgres.go @@ -31,7 +31,7 @@ func (db *Postgres) TestConnection(urlstr string) error { } func (db *Postgres) Connect(urlstr string) (err error) { - db.SetProvider("postgres") + db.SetProvider(PostgresDriver) db.Connection, err = dburl.Open(urlstr) if err != nil { diff --git a/drivers/sqlite.go b/drivers/sqlite.go index 24fc476..9e674b8 100644 --- a/drivers/sqlite.go +++ b/drivers/sqlite.go @@ -23,7 +23,7 @@ func (db *SQLite) TestConnection(urlstr string) (err error) { } func (db *SQLite) Connect(urlstr string) (err error) { - db.SetProvider("sqlite3") + db.SetProvider(SQLiteDriver) db.Connection, err = sql.Open("sqlite", urlstr) if err != nil {