-
-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathMongoDBPlugin.swift
More file actions
132 lines (123 loc) · 5.73 KB
/
MongoDBPlugin.swift
File metadata and controls
132 lines (123 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// MongoDBPlugin.swift
// TablePro
//
import Foundation
import TableProPluginKit
final class MongoDBPlugin: NSObject, TableProPlugin, DriverPlugin {
static let pluginName = "MongoDB Driver"
static let pluginVersion = "1.0.0"
static let pluginDescription = "MongoDB support via libmongoc C driver"
static let capabilities: [PluginCapability] = [.databaseDriver]
static let databaseTypeId = "MongoDB"
static let databaseDisplayName = "MongoDB"
static let iconName = "mongodb-icon"
static let defaultPort = 27017
static let additionalConnectionFields: [ConnectionField] = [
ConnectionField(id: "mongoAuthSource", label: "Auth Database", placeholder: "admin"),
ConnectionField(
id: "mongoReadPreference",
label: "Read Preference",
fieldType: .dropdown(options: [
.init(value: "", label: "Default"),
.init(value: "primary", label: "Primary"),
.init(value: "primaryPreferred", label: "Primary Preferred"),
.init(value: "secondary", label: "Secondary"),
.init(value: "secondaryPreferred", label: "Secondary Preferred"),
.init(value: "nearest", label: "Nearest"),
])
),
ConnectionField(
id: "mongoWriteConcern",
label: "Write Concern",
fieldType: .dropdown(options: [
.init(value: "", label: "Default"),
.init(value: "majority", label: "Majority"),
.init(value: "1", label: "1"),
.init(value: "2", label: "2"),
.init(value: "3", label: "3"),
])
),
ConnectionField(
id: "mongoUseSrv",
label: "Use SRV Record",
defaultValue: "false",
fieldType: .toggle,
section: .advanced
),
ConnectionField(
id: "mongoAuthMechanism",
label: "Auth Mechanism",
fieldType: .dropdown(options: [
.init(value: "", label: "Default"),
.init(value: "SCRAM-SHA-1", label: "SCRAM-SHA-1"),
.init(value: "SCRAM-SHA-256", label: "SCRAM-SHA-256"),
.init(value: "MONGODB-X509", label: "X.509"),
.init(value: "MONGODB-AWS", label: "AWS IAM"),
]),
section: .authentication
),
ConnectionField(
id: "mongoReplicaSet",
label: "Replica Set",
section: .advanced
),
]
// MARK: - UI/Capability Metadata
static let requiresAuthentication = false
static let urlSchemes: [String] = ["mongodb", "mongodb+srv"]
static let brandColorHex = "#00ED63"
static let queryLanguageName = "MQL"
static let editorLanguage: EditorLanguage = .javascript
static let supportsForeignKeys = false
static let supportsSchemaEditing = false
static let systemDatabaseNames: [String] = ["admin", "local", "config"]
static let tableEntityName = "Collections"
static let supportsForeignKeyDisable = false
static let immutableColumns: [String] = ["_id"]
static let supportsReadOnlyMode = false
static let databaseGroupingStrategy: GroupingStrategy = .flat
static let columnTypesByCategory: [String: [String]] = [
"String": ["string", "objectId", "regex"],
"Number": ["int", "long", "double", "decimal"],
"Date": ["date", "timestamp"],
"Binary": ["binData"],
"Boolean": ["bool"],
"Array": ["array"],
"Object": ["object"],
"Null": ["null"],
"Other": ["javascript", "minKey", "maxKey"]
]
static let structureColumnFields: [StructureColumnField] = [.name, .type, .nullable]
static let defaultPrimaryKeyColumn: String? = "_id"
static let sqlDialect: SQLDialectDescriptor? = nil
static var statementCompletions: [CompletionEntry] {
[
CompletionEntry(label: "db.", insertText: "db."),
CompletionEntry(label: "db.runCommand", insertText: "db.runCommand"),
CompletionEntry(label: "db.adminCommand", insertText: "db.adminCommand"),
CompletionEntry(label: "db.createView", insertText: "db.createView"),
CompletionEntry(label: "db.createCollection", insertText: "db.createCollection"),
CompletionEntry(label: "show dbs", insertText: "show dbs"),
CompletionEntry(label: "show collections", insertText: "show collections"),
CompletionEntry(label: ".find", insertText: ".find"),
CompletionEntry(label: ".findOne", insertText: ".findOne"),
CompletionEntry(label: ".aggregate", insertText: ".aggregate"),
CompletionEntry(label: ".insertOne", insertText: ".insertOne"),
CompletionEntry(label: ".insertMany", insertText: ".insertMany"),
CompletionEntry(label: ".updateOne", insertText: ".updateOne"),
CompletionEntry(label: ".updateMany", insertText: ".updateMany"),
CompletionEntry(label: ".deleteOne", insertText: ".deleteOne"),
CompletionEntry(label: ".deleteMany", insertText: ".deleteMany"),
CompletionEntry(label: ".replaceOne", insertText: ".replaceOne"),
CompletionEntry(label: ".findOneAndUpdate", insertText: ".findOneAndUpdate"),
CompletionEntry(label: ".findOneAndReplace", insertText: ".findOneAndReplace"),
CompletionEntry(label: ".findOneAndDelete", insertText: ".findOneAndDelete"),
CompletionEntry(label: ".countDocuments", insertText: ".countDocuments"),
CompletionEntry(label: ".createIndex", insertText: ".createIndex")
]
}
func createDriver(config: DriverConnectionConfig) -> any PluginDatabaseDriver {
MongoDBPluginDriver(config: config)
}
}