Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"strconv"
|
|
)
|
|
|
|
// Every cell carries its SQLite storage class: JSON alone cannot distinguish
|
|
// BLOBs from text, or carry int64 without losing JavaScript precision.
|
|
type wireValue struct {
|
|
Type string `json:"type"`
|
|
Integer string `json:"integer,omitzero"`
|
|
Real float64 `json:"real,omitzero"`
|
|
Special string `json:"special,omitzero"`
|
|
Text string `json:"text,omitzero"`
|
|
Blob []byte `json:"blob,omitzero"`
|
|
}
|
|
type wireStatement struct {
|
|
SQL string `json:"sql"`
|
|
Args []wireValue `json:"args"`
|
|
}
|
|
type wireResult struct {
|
|
Changes int64 `json:"changes"`
|
|
LastInsertID string `json:"lastInsertId"`
|
|
}
|
|
type wireRows struct {
|
|
Columns []string `json:"columns"`
|
|
Rows [][]wireValue `json:"rows"`
|
|
}
|
|
|
|
func parameters(values []wireValue) ([]any, error) {
|
|
args := make([]any, len(values))
|
|
for i, value := range values {
|
|
switch value.Type {
|
|
case "null":
|
|
args[i] = nil
|
|
case "integer":
|
|
n, err := strconv.ParseInt(value.Integer, 10, 64)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("sqlite: parameter %d: invalid signed 64-bit integer", i+1)
|
|
}
|
|
args[i] = n
|
|
case "real":
|
|
if value.Special != "" || math.IsNaN(value.Real) || math.IsInf(value.Real, 0) {
|
|
return nil, fmt.Errorf("sqlite: parameter %d: number must be finite", i+1)
|
|
}
|
|
args[i] = value.Real
|
|
case "text":
|
|
args[i] = value.Text
|
|
case "blob":
|
|
args[i] = value.Blob
|
|
default:
|
|
return nil, fmt.Errorf("sqlite: parameter %d: unknown value type %q", i+1, value.Type)
|
|
}
|
|
}
|
|
return args, nil
|
|
}
|
|
|
|
func resultWire(result Result) wireResult {
|
|
return wireResult{Changes: result.Changes, LastInsertID: strconv.FormatInt(result.LastInsertID, 10)}
|
|
}
|
|
|
|
func rowsWire(rows Rows) wireRows {
|
|
result := wireRows{Columns: rows.Columns, Rows: make([][]wireValue, len(rows.Values))}
|
|
for i, row := range rows.Values {
|
|
result.Rows[i] = make([]wireValue, len(row))
|
|
for j, cell := range row {
|
|
value := wireValue{Type: "null"}
|
|
switch v := cell.(type) {
|
|
case int64:
|
|
value.Type, value.Integer = "integer", strconv.FormatInt(v, 10)
|
|
case float64:
|
|
value.Type, value.Real = "real", v
|
|
if math.IsInf(v, 0) || math.IsNaN(v) {
|
|
value.Real = 0
|
|
switch {
|
|
case math.IsInf(v, 1):
|
|
value.Special = "Infinity"
|
|
case math.IsInf(v, -1):
|
|
value.Special = "-Infinity"
|
|
default:
|
|
value.Special = "NaN"
|
|
}
|
|
}
|
|
case string:
|
|
value.Type, value.Text = "text", v
|
|
case []byte:
|
|
value.Type, value.Blob = "blob", v
|
|
}
|
|
result.Rows[i][j] = value
|
|
}
|
|
}
|
|
return result
|
|
}
|