Skip to content

Commit

Permalink
add user flag
Browse files Browse the repository at this point in the history
returns username
  • Loading branch information
doneill committed Dec 17, 2023
1 parent 8aa4eba commit cbebbc8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
)

var dbUser bool
var displayTables bool

// ----------------------------------------------
Expand Down Expand Up @@ -39,6 +40,10 @@ func open(file string) {
}

switch {
case dbUser:
var user []data.Accounts_User
db.First(&user)
fmt.Println(user[0].Username)
case displayTables:
tables, err := data.GetTables(*db)
if err != nil {
Expand Down Expand Up @@ -67,5 +72,6 @@ func open(file string) {

func init() {
rootCmd.AddCommand(openCmd)
openCmd.Flags().BoolVarP(&dbUser, "user", "u", false, "Display database account user")
openCmd.Flags().BoolVarP(&displayTables, "tables", "t", false, "Display all database tables")
}
26 changes: 26 additions & 0 deletions data/tables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package data

// ----------------------------------------------
// table stucts
// ----------------------------------------------

type Accounts_User struct {
ID int `gorm:"primaryKey;autoIncrement"`
RemoteID string `json:"remote_id" gorm:"column:remote_id"`
Username string `json:"username" gorm:"column:username"`
FirstName string `json:"first_name" gorm:"column:first_name"`
LastName string `json:"last_name" gorm:"column:last_name"`
Email string `json:"email" gorm:"column:email"`
}

// ----------------------------------------------
// table configurations
// ----------------------------------------------

type Tabler interface {
TableName() string
}

func (Accounts_User) TableName() string {
return "accounts_user"
}

0 comments on commit cbebbc8

Please sign in to comment.