mirror of
https://github.com/quitesimpleorg/hs9001.git
synced 2024-12-30 14:03:44 +01:00
Compare commits
No commits in common. "e1375f237c42345b9c22caeb885d6b44e14699ff" and "d0e07640e8cdb74939b647c801a7353d41897040" have entirely different histories.
e1375f237c
...
d0e07640e8
17
main.go
17
main.go
@ -66,11 +66,6 @@ func migrateDatabase(conn *sql.DB, currentVersion int) {
|
|||||||
migrations := []string{
|
migrations := []string{
|
||||||
"ALTER TABLE history ADD COLUMN workdir varchar(4096) DEFAULT ''",
|
"ALTER TABLE history ADD COLUMN workdir varchar(4096) DEFAULT ''",
|
||||||
"ALTER TABLE history ADD COLUMN retval integer DEFAULT -9001",
|
"ALTER TABLE history ADD COLUMN retval integer DEFAULT -9001",
|
||||||
"ALTER TABLE history ADD COLUMN unix_tmp integer",
|
|
||||||
"UPDATE history SET unix_tmp = strftime('%s', timestamp)",
|
|
||||||
"DROP VIEW count_by_date",
|
|
||||||
"ALTER TABLE history DROP COLUMN timestamp",
|
|
||||||
"ALTER TABLE history RENAME COLUMN unix_tmp TO timestamp",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(len(migrations) > currentVersion) {
|
if !(len(migrations) > currentVersion) {
|
||||||
@ -169,7 +164,7 @@ type searchopts struct {
|
|||||||
func search(conn *sql.DB, opts searchopts) list.List {
|
func search(conn *sql.DB, opts searchopts) list.List {
|
||||||
args := make([]interface{}, 0)
|
args := make([]interface{}, 0)
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
sb.WriteString("SELECT id, command, workdir, user, hostname, retval, timestamp ")
|
sb.WriteString("SELECT id, command, workdir, user, hostname, retval, strftime(\"%s\", timestamp) ")
|
||||||
sb.WriteString("FROM history ")
|
sb.WriteString("FROM history ")
|
||||||
sb.WriteString("WHERE 1=1 ") //1=1 so we can append as many AND foo as we want, or none
|
sb.WriteString("WHERE 1=1 ") //1=1 so we can append as many AND foo as we want, or none
|
||||||
|
|
||||||
@ -182,11 +177,11 @@ func search(conn *sql.DB, opts searchopts) list.List {
|
|||||||
args = append(args, opts.workdir)
|
args = append(args, opts.workdir)
|
||||||
}
|
}
|
||||||
if opts.after != nil {
|
if opts.after != nil {
|
||||||
sb.WriteString("AND timestamp > ? ")
|
sb.WriteString("AND timestamp > datetime(?, 'unixepoch') ")
|
||||||
args = append(args, opts.after.Unix())
|
args = append(args, opts.after.Unix())
|
||||||
}
|
}
|
||||||
if opts.before != nil {
|
if opts.before != nil {
|
||||||
sb.WriteString("AND timestamp < ? ")
|
sb.WriteString("AND timestamp < datetime(?, 'unixepoch') ")
|
||||||
args = append(args, opts.before.Unix())
|
args = append(args, opts.before.Unix())
|
||||||
}
|
}
|
||||||
if opts.retval != nil {
|
if opts.retval != nil {
|
||||||
@ -239,7 +234,7 @@ func delete(conn *sql.DB, entryId uint32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func add(conn *sql.DB, entry HistoryEntry) {
|
func add(conn *sql.DB, entry HistoryEntry) {
|
||||||
stmt, err := conn.Prepare("INSERT INTO history (user, command, hostname, workdir, timestamp, retval) VALUES (?, ?, ?, ?, ?,?)")
|
stmt, err := conn.Prepare("INSERT INTO history (user, command, hostname, workdir, timestamp, retval) VALUES (?, ?, ?, ?, datetime(?, 'unixepoch'),?)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
@ -411,7 +406,6 @@ func main() {
|
|||||||
results := search(conn, opts)
|
results := search(conn, opts)
|
||||||
|
|
||||||
previousCmd := ""
|
previousCmd := ""
|
||||||
previousReturn := -1
|
|
||||||
|
|
||||||
fi, err := os.Stdout.Stat()
|
fi, err := os.Stdout.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -429,7 +423,7 @@ func main() {
|
|||||||
if !ok {
|
if !ok {
|
||||||
log.Panic("Failed to retrieve entries")
|
log.Panic("Failed to retrieve entries")
|
||||||
}
|
}
|
||||||
if !distinct || !(previousCmd == entry.cmd && previousReturn == entry.retval) {
|
if !distinct || previousCmd != entry.cmd {
|
||||||
prefix := ""
|
prefix := ""
|
||||||
postfix := ""
|
postfix := ""
|
||||||
if printColors && entry.retval != 0 {
|
if printColors && entry.retval != 0 {
|
||||||
@ -439,7 +433,6 @@ func main() {
|
|||||||
fmt.Printf("%s%s%s\n", prefix, entry.cmd, postfix)
|
fmt.Printf("%s%s%s\n", prefix, entry.cmd, postfix)
|
||||||
}
|
}
|
||||||
previousCmd = entry.cmd
|
previousCmd = entry.cmd
|
||||||
previousReturn = entry.retval
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmd == "delete" {
|
if cmd == "delete" {
|
||||||
|
Loading…
Reference in New Issue
Block a user