Skip to content

Commit

Permalink
Rename files to the more commenly used (in Go projects) snake_case
Browse files Browse the repository at this point in the history
In addition one struct field is renamed to follow the initialisms
guideline: https://go.dev/wiki/CodeReviewComments#initialisms
  • Loading branch information
svanharmelen committed Dec 12, 2024
1 parent d4cd01f commit f69ecc7
Show file tree
Hide file tree
Showing 28 changed files with 74 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions/setup-go@v5

- name: Golangci-lint
uses: golangci/golangci-lint-action@v6.0.1
uses: golangci/golangci-lint-action@v6

- name: Test
run: go test -v ./...
Expand Down
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ linters-settings:
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
- name: errorf

# enforces conventions on source file names
- name: filename-format
arguments: ["^[_a-z][_a-z0-9]*\\.go$"]

# incrementing an integer variable by 1 is recommended to be done using the `++` operator
- name: increment-decrement

Expand Down Expand Up @@ -140,6 +144,7 @@ linters-settings:

# warns when initialism, variable or package naming conventions are not followed.
- name: var-naming
arguments: [[], ["DB", "DML"]]

# if-then-else conditional with identical implementations in both branches is an error.
- name: identical-branches
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 8 additions & 6 deletions components/ArgConnection.go → components/arg_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ func InitFromArg(connectionString string) error {
DBName: DBName,
URL: connectionString,
}
var newDbDriver drivers.Driver

var newDBDriver drivers.Driver
switch connection.Provider {
case drivers.DriverMySQL:
newDbDriver = &drivers.MySQL{}
newDBDriver = &drivers.MySQL{}
case drivers.DriverPostgres:
newDbDriver = &drivers.Postgres{}
newDBDriver = &drivers.Postgres{}
case drivers.DriverSqlite:
newDbDriver = &drivers.SQLite{}
newDBDriver = &drivers.SQLite{}
}
err = newDbDriver.Connect(connection.URL)

err = newDBDriver.Connect(connection.URL)
if err != nil {
return fmt.Errorf("Could not connect to database %s: %s", connectionString, err)
}
MainPages.AddAndSwitchToPage(connection.URL, NewHomePage(connection, newDbDriver).Flex, true)
MainPages.AddAndSwitchToPage(connection.URL, NewHomePage(connection, newDBDriver).Flex, true)

return nil
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions components/Home.go → components/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Home struct {
HelpModal *HelpModal
DBDriver drivers.Driver
FocusedWrapper string
ListOfDBChanges []models.DbDmlChange
ListOfDBChanges []models.DBDMLChange
}

func NewHomePage(connection models.Connection, dbdriver drivers.Driver) *Home {
Expand All @@ -43,7 +43,7 @@ func NewHomePage(connection models.Connection, dbdriver drivers.Driver) *Home {
HelpStatus: NewHelpStatus(),
HelpModal: NewHelpModal(),
DBDriver: dbdriver,
ListOfDBChanges: []models.DbDmlChange{},
ListOfDBChanges: []models.DBDMLChange{},
}

go home.subscribeToTreeChanges()
Expand Down Expand Up @@ -317,7 +317,7 @@ func (home *Home) homeInputCapture(event *tcell.EventKey) *tcell.EventKey {
if err != nil {
table.SetError(err.Error(), nil)
} else {
home.ListOfDBChanges = []models.DbDmlChange{}
home.ListOfDBChanges = []models.DBDMLChange{}

table.FetchRecords(nil)
home.Tree.ForceRemoveHighlight()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 38 additions & 38 deletions components/ResultsTable.go → components/results_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

type ResultsTableState struct {
listOfDbChanges *[]models.DbDmlChange
listOfDBChanges *[]models.DBDMLChange
error string
currentSort string
databaseName string
Expand Down Expand Up @@ -53,7 +53,7 @@ type ResultsTable struct {
DBDriver drivers.Driver
}

func NewResultsTable(listOfDbChanges *[]models.DbDmlChange, tree *Tree, dbdriver drivers.Driver) *ResultsTable {
func NewResultsTable(listOfDBChanges *[]models.DBDMLChange, tree *Tree, dbdriver drivers.Driver) *ResultsTable {
state := &ResultsTableState{
records: [][]string{},
columns: [][]string{},
Expand All @@ -62,7 +62,7 @@ func NewResultsTable(listOfDbChanges *[]models.DbDmlChange, tree *Tree, dbdriver
indexes: [][]string{},
isEditing: false,
isLoading: false,
listOfDbChanges: listOfDbChanges,
listOfDBChanges: listOfDBChanges,
showSidebar: false,
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func (table *ResultsTable) subscribeToSidebarChanges() {
}

logger.Info("eventSidebarCommitEditing", map[string]any{"cellValue": cellValue, "params": params, "rowIndex": row, "changedColumnIndex": changedColumnIndex})
table.AppendNewChange(models.DmlUpdateType, row, changedColumnIndex, cellValue)
table.AppendNewChange(models.DMLUpdateType, row, changedColumnIndex, cellValue)

App.ForceDraw()
case eventSidebarError:
Expand Down Expand Up @@ -262,10 +262,10 @@ func (table *ResultsTable) AddRows(rows [][]string) {
}

func (table *ResultsTable) AddInsertedRows() {
inserts := make([]models.DbDmlChange, 0)
inserts := make([]models.DBDMLChange, 0)

for _, change := range *table.state.listOfDbChanges {
if change.Type == models.DmlInsertType {
for _, change := range *table.state.listOfDBChanges {
if change.Type == models.DMLInsertType {
inserts = append(inserts, change)
}
}
Expand Down Expand Up @@ -418,7 +418,7 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
isAnInsertedRow := false
indexOfInsertedRow := -1

for i, insertedRow := range *table.state.listOfDbChanges {
for i, insertedRow := range *table.state.listOfDBChanges {
cellReference := table.GetCell(selectedRowIndex, 0).GetReference()

if cellReference != nil && insertedRow.PrimaryKeyInfo[0].Value == cellReference {
Expand All @@ -428,7 +428,7 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
}

if isAnInsertedRow {
*table.state.listOfDbChanges = append((*table.state.listOfDbChanges)[:indexOfInsertedRow], (*table.state.listOfDbChanges)[indexOfInsertedRow+1:]...)
*table.state.listOfDBChanges = append((*table.state.listOfDBChanges)[:indexOfInsertedRow], (*table.state.listOfDBChanges)[indexOfInsertedRow+1:]...)
table.RemoveRow(selectedRowIndex)
if selectedRowIndex-1 != 0 {
table.Select(selectedRowIndex-1, 0)
Expand All @@ -438,7 +438,7 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
}
}
} else {
table.AppendNewChange(models.DmlDeleteType, selectedRowIndex, -1, models.CellValue{})
table.AppendNewChange(models.DMLDeleteType, selectedRowIndex, -1, models.CellValue{})
}

}
Expand All @@ -455,7 +455,7 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
table.FinishSettingValue()

if selection >= 0 {
table.AppendNewChange(models.DmlUpdateType, selectedRowIndex, selectedColumnIndex, models.CellValue{Type: selection, Value: value, Column: table.GetColumnNameByIndex(selectedColumnIndex)})
table.AppendNewChange(models.DMLUpdateType, selectedRowIndex, selectedColumnIndex, models.CellValue{Type: selection, Value: value, Column: table.GetColumnNameByIndex(selectedColumnIndex)})
}
})

Expand Down Expand Up @@ -967,7 +967,7 @@ func (table *ResultsTable) StartEditingCell(row int, col int, callback func(newV
cell.SetText(newValue)

if currentValue != newValue {
table.AppendNewChange(models.DmlUpdateType, row, col, models.CellValue{Type: models.String, Value: newValue, Column: columnName, TableColumnIndex: col, TableRowIndex: row})
table.AppendNewChange(models.DMLUpdateType, row, col, models.CellValue{Type: models.String, Value: newValue, Column: columnName, TableColumnIndex: col, TableRowIndex: row})
}

switch key {
Expand Down Expand Up @@ -1011,8 +1011,8 @@ func (table *ResultsTable) StartEditingCell(row int, col int, callback func(newV
}

func (table *ResultsTable) CheckIfRowIsInserted(rowID string) bool {
for _, dmlChange := range *table.state.listOfDbChanges {
if dmlChange.Type == models.DmlInsertType && dmlChange.PrimaryKeyInfo[0].Value == rowID {
for _, dmlChange := range *table.state.listOfDBChanges {
if dmlChange.Type == models.DMLInsertType && dmlChange.PrimaryKeyInfo[0].Value == rowID {
return true
}
}
Expand All @@ -1021,19 +1021,19 @@ func (table *ResultsTable) CheckIfRowIsInserted(rowID string) bool {
}

func (table *ResultsTable) MutateInsertedRowCell(rowID string, newValue models.CellValue) {
for i, dmlChange := range *table.state.listOfDbChanges {
if dmlChange.PrimaryKeyInfo[0].Value == rowID && dmlChange.Type == models.DmlInsertType {
for i, dmlChange := range *table.state.listOfDBChanges {
if dmlChange.PrimaryKeyInfo[0].Value == rowID && dmlChange.Type == models.DMLInsertType {
for j, v := range dmlChange.Values {
if v.Column == newValue.Column {
(*table.state.listOfDbChanges)[i].Values[j] = newValue
(*table.state.listOfDBChanges)[i].Values[j] = newValue
break
}
}
}
}
}

func (table *ResultsTable) AppendNewChange(changeType models.DmlType, rowIndex int, colIndex int, value models.CellValue) {
func (table *ResultsTable) AppendNewChange(changeType models.DMLType, rowIndex int, colIndex int, value models.CellValue) {
databaseName := table.GetDatabaseName()
tableName := table.GetTableName()

Expand All @@ -1058,7 +1058,7 @@ func (table *ResultsTable) AppendNewChange(changeType models.DmlType, rowIndex i
return
}

if changeType == models.DmlUpdateType {
if changeType == models.DMLUpdateType {
switch value.Type {
case models.Null, models.Empty, models.Default:
tableCell.SetText(value.Value.(string))
Expand All @@ -1067,7 +1067,7 @@ func (table *ResultsTable) AppendNewChange(changeType models.DmlType, rowIndex i
}
}

for i, dmlChange := range *table.state.listOfDbChanges {
for i, dmlChange := range *table.state.listOfDBChanges {
changeExistOnSameCell := false

for _, value := range dmlChange.Values {
Expand All @@ -1092,27 +1092,27 @@ func (table *ResultsTable) AppendNewChange(changeType models.DmlType, rowIndex i
}

switch changeType {
case models.DmlUpdateType:
case models.DMLUpdateType:
originalValue := table.GetRecords()[rowIndex][colIndex]

if changeForColExists {
if originalValue == value.Value {
if len((*table.state.listOfDbChanges)[i].Values) == 1 {
*table.state.listOfDbChanges = append((*table.state.listOfDbChanges)[:i], (*table.state.listOfDbChanges)[i+1:]...)
if len((*table.state.listOfDBChanges)[i].Values) == 1 {
*table.state.listOfDBChanges = append((*table.state.listOfDBChanges)[:i], (*table.state.listOfDBChanges)[i+1:]...)
} else {
(*table.state.listOfDbChanges)[i].Values = append((*table.state.listOfDbChanges)[i].Values[:valueIndex], (*table.state.listOfDbChanges)[i].Values[valueIndex+1:]...)
(*table.state.listOfDBChanges)[i].Values = append((*table.state.listOfDBChanges)[i].Values[:valueIndex], (*table.state.listOfDBChanges)[i].Values[valueIndex+1:]...)
}
table.SetCellColor(rowIndex, colIndex, app.Styles.PrimitiveBackgroundColor)
} else {
(*table.state.listOfDbChanges)[i].Values[valueIndex] = value
(*table.state.listOfDBChanges)[i].Values[valueIndex] = value
}
} else {
(*table.state.listOfDbChanges)[i].Values = append((*table.state.listOfDbChanges)[i].Values, value)
(*table.state.listOfDBChanges)[i].Values = append((*table.state.listOfDBChanges)[i].Values, value)
table.SetCellColor(rowIndex, colIndex, colorTableChange)
}

case models.DmlDeleteType:
*table.state.listOfDbChanges = append((*table.state.listOfDbChanges)[:i], (*table.state.listOfDbChanges)[i+1:]...)
case models.DMLDeleteType:
*table.state.listOfDBChanges = append((*table.state.listOfDBChanges)[:i], (*table.state.listOfDBChanges)[i+1:]...)
table.SetRowColor(rowIndex, app.Styles.PrimitiveBackgroundColor)
}
}
Expand All @@ -1121,26 +1121,26 @@ func (table *ResultsTable) AppendNewChange(changeType models.DmlType, rowIndex i
if !dmlChangeAlreadyExists {

switch changeType {
case models.DmlDeleteType:
case models.DMLDeleteType:
table.SetRowColor(rowIndex, colorTableDelete)
case models.DmlUpdateType:
case models.DMLUpdateType:
tableCell.SetStyle(tcell.StyleDefault.Background(colorTableChange))
table.SetCellColor(rowIndex, colIndex, colorTableChange)
}

newDmlChange := models.DbDmlChange{
newDMLChange := models.DBDMLChange{
Type: changeType,
Database: databaseName,
Table: tableName,
Values: []models.CellValue{value},
PrimaryKeyInfo: rowPrimaryKeyInfo,
}

*table.state.listOfDbChanges = append(*table.state.listOfDbChanges, newDmlChange)
*table.state.listOfDBChanges = append(*table.state.listOfDBChanges, newDMLChange)

}

logger.Info("AppendNewChange", map[string]any{"listOfDbChanges": *table.state.listOfDbChanges})
logger.Info("AppendNewChange", map[string]any{"listOfDbChanges": *table.state.listOfDBChanges})
}

func (table *ResultsTable) GetPrimaryKeyValue(rowIndex int) []models.PrimaryKeyInfo {
Expand Down Expand Up @@ -1179,15 +1179,15 @@ func (table *ResultsTable) appendNewRow() {
}
}

newInsert := models.DbDmlChange{
Type: models.DmlInsertType,
newInsert := models.DBDMLChange{
Type: models.DMLInsertType,
Database: table.GetDatabaseName(),
Table: table.GetTableName(),
Values: newRow,
PrimaryKeyInfo: []models.PrimaryKeyInfo{{Name: "", Value: newRowUUID}},
}

*table.state.listOfDbChanges = append(*table.state.listOfDbChanges, newInsert)
*table.state.listOfDBChanges = append(*table.state.listOfDBChanges, newInsert)

table.AppendNewRow(newRow, newRowTableIndex, newRowUUID)

Expand Down Expand Up @@ -1353,8 +1353,8 @@ func (table *ResultsTable) UpdateSidebar() {

pendingEditExist := false

for _, dmlChange := range *table.state.listOfDbChanges {
if dmlChange.Type == models.DmlUpdateType {
for _, dmlChange := range *table.state.listOfDBChanges {
if dmlChange.Type == models.DMLUpdateType {
for _, v := range dmlChange.Values {
if v.Column == name && v.TableRowIndex == selectedRow && v.TableColumnIndex == i-1 {
pendingEditExist = true
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Driver interface {
DeleteRecord(database, table string, primaryKeyColumnName, primaryKeyValue string) error
ExecuteDMLStatement(query string) (string, error)
ExecuteQuery(query string) ([][]string, error)
ExecutePendingChanges(changes []models.DbDmlChange) error
ExecutePendingChanges(changes []models.DBDMLChange) error
SetProvider(provider string) // NOTE: This is used to get the primary key from the database table until i find a better way to do it. See ResultsTable.go GetPrimaryKeyValue function
GetProvider() string
GetPrimaryKeyColumnNames(database, table string) ([]string, error)
Expand Down
8 changes: 4 additions & 4 deletions drivers/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (db *MySQL) ExecuteDMLStatement(query string) (result string, err error) {
return fmt.Sprintf("%d rows affected", rowsAffected), nil
}

func (db *MySQL) ExecutePendingChanges(changes []models.DbDmlChange) (err error) {
func (db *MySQL) ExecutePendingChanges(changes []models.DBDMLChange) (err error) {
var queries []models.Query

for _, change := range changes {
Expand Down Expand Up @@ -479,7 +479,7 @@ func (db *MySQL) ExecutePendingChanges(changes []models.DbDmlChange) (err error)
}

switch change.Type {
case models.DmlInsertType:
case models.DMLInsertType:
queryStr := "INSERT INTO "
queryStr += db.formatTableName(change.Database, change.Table)
queryStr += fmt.Sprintf(" (%s) VALUES (%s)", strings.Join(columnNames, ", "), strings.Join(valuesPlaceholder, ", "))
Expand All @@ -490,7 +490,7 @@ func (db *MySQL) ExecutePendingChanges(changes []models.DbDmlChange) (err error)
}

queries = append(queries, newQuery)
case models.DmlUpdateType:
case models.DMLUpdateType:
queryStr := "UPDATE "
queryStr += db.formatTableName(change.Database, change.Table)

Expand Down Expand Up @@ -521,7 +521,7 @@ func (db *MySQL) ExecutePendingChanges(changes []models.DbDmlChange) (err error)
}

queries = append(queries, newQuery)
case models.DmlDeleteType:
case models.DMLDeleteType:
queryStr := "DELETE FROM "
queryStr += db.formatTableName(change.Database, change.Table)

Expand Down
Loading

0 comments on commit f69ecc7

Please sign in to comment.