added typeaheead and introspetion
This commit is contained in:
@@ -197,6 +197,21 @@ final class DatabaseModel: ObservableObject {
|
||||
let views: [String]
|
||||
let columnsByTable: [String: [IntrospectedColumn]]
|
||||
}
|
||||
// Resolve USE statements from the editor buffer even before Run is pressed.
|
||||
// The completion provider must not depend on navigator selection alone.
|
||||
var completionDatabase: String {
|
||||
let pattern = #"(?im)^\s*USE\s+`?([A-Za-z_][A-Za-z0-9_]*)`?\s*;?"#
|
||||
if let regex = try? NSRegularExpression(pattern: pattern) {
|
||||
let value = sql as NSString
|
||||
let range = NSRange(location: 0, length: value.length)
|
||||
if let match = regex.matches(in: sql, range: range).last,
|
||||
match.numberOfRanges > 1 {
|
||||
return value.substring(with: match.range(at: 1))
|
||||
}
|
||||
}
|
||||
return selectedDatabase.isEmpty ? (selected?.database ?? "") : selectedDatabase
|
||||
}
|
||||
|
||||
@Published private(set) var introspections: [String: SchemaIntrospection] = [:]
|
||||
private let introspectionStorageKey = "DBSyn.introspection.snapshots.v2"
|
||||
private func persistIntrospections() {
|
||||
@@ -581,6 +596,7 @@ final class DatabaseModel: ObservableObject {
|
||||
selectedDatabase = usedSchema
|
||||
// Metadata is cached in memory for native SQL completion.
|
||||
loadTables(database: usedSchema)
|
||||
introspect(database: usedSchema)
|
||||
}
|
||||
}
|
||||
if listingDatabases {
|
||||
|
||||
Reference in New Issue
Block a user