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
Showing
7 changed files
with
130 additions
and
105 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/jinzhu/gorm" | ||
_ "github.com/jinzhu/gorm/dialects/sqlite" | ||
homedir "github.com/mitchellh/go-homedir" | ||
) | ||
|
||
type Issue struct { | ||
ID int `gorm:"primary_key"` | ||
Number int | ||
Title string | ||
RepoOwner string `gorm:"column:repoOwner"` | ||
RepoName string `gorm:column:repoName` | ||
State string | ||
Locked bool | ||
Comments int | ||
CreatedAt string `gorm:"column:createdAt"` | ||
UpdatedAt string `gorm:"column:updatedAt"` | ||
ClosedAt NullStringJSON `gorm:"column:closedAt"` | ||
IsPullRequest bool `gorm:"column:isPullRequest"` | ||
Body string | ||
AlreadyRead bool `gorm:"column:alreadyRead"` | ||
Merged NullBoolJSON | ||
|
||
User *User | ||
Labels []*Label | ||
Assignees []*User | ||
} | ||
|
||
type Label struct { | ||
ID int | ||
Name string | ||
Color string | ||
Default bool | ||
} | ||
|
||
type User struct { | ||
ID int | ||
Login string | ||
AvatarURL string | ||
} | ||
|
||
type Account struct { | ||
ID int | ||
DisplayName string `gorm:"column:displayName"` | ||
UrlBase string `gorm:"column:urlBase"` | ||
ApiUrlBase string `gorm:"column:apiUrlBase"` | ||
AccessToken string `gorm:"column:accessToken"` | ||
|
||
Channels []Channel | ||
} | ||
|
||
type Channel struct { | ||
ID int | ||
DisplayName string `gorm:"column:displayName"` | ||
System sql.NullString | ||
QueriesRow string `gorm:"column:queries"` | ||
Queries []string | ||
AccountID int `gorm:"column:accountID"` | ||
} | ||
|
||
func SelectAccounts() ([]Account, error) { | ||
accounts := make([]Account, 0) | ||
if err := gormConn.Preload("Channels").Find(&accounts).Error; err != nil { | ||
return nil, err | ||
} | ||
return accounts, nil | ||
} | ||
|
||
func init() { | ||
fname, err := homedir.Expand("~/.cache/korat/development.sqlite3") | ||
if err != nil { | ||
panic(err) | ||
} | ||
db, err := gorm.Open("sqlite3", fname) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Will not set CreatedAt and UpdatedAt on .Create() call | ||
db.Callback().Create().Remove("gorm:update_time_stamp") | ||
// Will not update UpdatedAt on .Save() call | ||
db.Callback().Update().Remove("gorm:update_time_stamp") | ||
db.LogMode(true) | ||
|
||
gormConn = db | ||
} | ||
|
||
var gormConn *gorm.DB |
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
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