Skip to content

Commit

Permalink
sql.t -> sql.p
Browse files Browse the repository at this point in the history
This parallels `ari.p` for previous REPL value
  • Loading branch information
semperos committed Jul 22, 2024
1 parent 2874661 commit faf329b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Ari takes the [Goal] programming language, wraps it in a custom CLI and provides
- Activate with `)sql` for read-only, `)sql!` for read/write modes. Execute `)goal` to return to the default Goal mode.
- Auto-completion of SQL keywords
- Help entries for SQL keywords (shown during auto-complete, still WIP)
- Results of last-run query/command set to the `sql.t` Goal global, so you can switch between `)sql` and `)goal` at the REPL to run queries via SQL and do data processing via Goal.
- Results of the last-run query/command set to the `sql.p` Goal global (for "SQL previous" and mirroring `ari.p`), so you can switch between `)sql` and `)goal` at the REPL to run queries via SQL and do data processing via Goal.

## To Do

Expand Down
20 changes: 13 additions & 7 deletions cmd/ari/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,16 @@ func (cliSystem *CliSystem) detectAriPrint() func(goal.V) {
if found {
if printFn.IsCallable() {
return func(v goal.V) {
printFn.ApplyAt(goalContext, v)
goalV := printFn.ApplyAt(goalContext, v)
// If an error occurs within the ari.print function, ensure it is printed like a Goal error.
if goalV.IsError() {
fmt.Fprintln(os.Stdout, goalV.Sprint(goalContext, false))
}
}
} else if printFn.IsFalse() {
return nil
}
fmt.Fprintf(os.Stderr, "Error: The ari.print value must be a callable, but encountered %q", printFn)
fmt.Fprintf(os.Stderr, "Error: The ari.print value must be a callable (or falsey), but encountered %q", printFn)
}
return nil
}
Expand All @@ -318,7 +324,7 @@ func (cliSystem *CliSystem) replEvalSQLReadOnly(line string) {
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to run SQL query %q\nDatabase Error:%s\n", line, err)
} else {
_, err := cliSystem.ariContext.GoalContext.Eval(`fmt.tbl[sql.t;*#'sql.t;#sql.t;"%.1f"]`)
_, err := cliSystem.ariContext.GoalContext.Eval(`fmt.tbl[sql.p;*#'sql.p;#sql.p;"%.1f"]`)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to print SQL query results via Goal evaluation: %v\n", err)
}
Expand All @@ -330,7 +336,7 @@ func (cliSystem *CliSystem) replEvalSQLReadWrite(line string) {
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to run SQL query %q\nDatabase Error:%s\n", line, err)
} else {
_, err := cliSystem.ariContext.GoalContext.Eval(`fmt.tbl[sql.t;*#'sql.t;#sql.t;"%.1f"]`)
_, err := cliSystem.ariContext.GoalContext.Eval(`fmt.tbl[sql.p;*#'sql.p;#sql.p;"%.1f"]`)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to print SQL exec results via Goal evaluation: %v\n", err)
}
Expand Down Expand Up @@ -397,8 +403,8 @@ func (cliSystem *CliSystem) sqlQuery(sqlQuery string, args []any) (goal.V, error
if err != nil {
return goal.V{}, err
}
// Last result table as sql.t in Goal, to support switching eval modes:
cliSystem.ariContext.GoalContext.AssignGlobal("sql.t", goalD)
// Last result table as sql.p in Goal, to support switching eval modes:
cliSystem.ariContext.GoalContext.AssignGlobal("sql.p", goalD)
return goalD, nil
}

Expand All @@ -414,7 +420,7 @@ func (cliSystem *CliSystem) sqlExec(sqlQuery string, args []any) (goal.V, error)
if err != nil {
return goal.V{}, err
}
cliSystem.ariContext.GoalContext.AssignGlobal("sql.t", goalD)
cliSystem.ariContext.GoalContext.AssignGlobal("sql.p", goalD)
return goalD, nil
}

Expand Down
6 changes: 3 additions & 3 deletions sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func sqlQMonadic(x goal.V, sqlDatabase *SQLDatabase, goalContext *goal.Context)
if err != nil {
return goal.NewPanicError(err)
}
goalContext.AssignGlobal("sql.t", goalD)
goalContext.AssignGlobal("sql.p", goalD)
return goalD
}

Expand Down Expand Up @@ -280,7 +280,7 @@ func sqlExecMonadic(x goal.V, sqlDatabase *SQLDatabase, goalContext *goal.Contex
if err != nil {
return goal.NewPanicError(err)
}
goalContext.AssignGlobal("sql.t", goalD)
goalContext.AssignGlobal("sql.p", goalD)
return goalD
}

Expand All @@ -298,7 +298,7 @@ func sqlExecDyadic(goalContext *goal.Context, x goal.V, args []goal.V) goal.V {
if err != nil {
return goal.NewPanicError(err)
}
goalContext.AssignGlobal("sql.t", goalD)
goalContext.AssignGlobal("sql.p", goalD)
return goalD
}

Expand Down

0 comments on commit faf329b

Please sign in to comment.