Thomas Anderson 是一位计算机程序员,他同时保持着作为“Neo”这个黑客的双重生活。 - Neo 和 Thomas 的组合
Theo 是一个用 Swift 编写的开源框架,它提供了一个与 Neo4j 互动的接口。
因为这个框架是开源的,所以最好在 Stack Overflow 上发帖并标记为 Theo。如果您
发现了一个错误,请提交一个问题或为一个功能或修复提交一个 PR。
您可以通过多种方式安装 Theo
###Swift 包管理器
将以下行添加到您的包依赖数组中
.Package(url: "https://github.com/GraphStory/neo4j-ios.git”, majorVersion: 3, minor: 0)
运行 swift build
以构建项目,现在包含 Theo 并准备好从源中使用
###CococaPods
将以下内容添加到您的 Podfile 中
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘10.0’
use_frameworks!
target '<Your Target Name>' do
pod ‘Theo’
end
运行 pod install
以配置您的更新工作区。打开生成的 .xcworkspace,您的项目现在已准备好使用 Theo
运行 carthage update --platform iOS
以构建框架,并将构建的 Theo.framework
拖入您的 Xcode 项目中。
###git 子模块
git submodule add [email protected]:GraphStory/neo4j-ios.git
注意 - 主机名后请不要包含斜杠
示例: http://www.hostname.com
不 是 http://www.hostname.com/
未认证
let theo: Client = Client(baseURL: "hostname.com")
认证
let theo: Client = Client(baseURL: "hostname.com", user: "username", pass: "password")
theo.metaDescription({(meta, error) in
print("meta in success \(meta) error \(error)")
})
theo.fetchNode("IDToFetch", completionBlock: {(node, error) in
print("meta in success \(node!.meta) node \(node) error \(error)")
})
无标签
let node = Node()
let randomString: String = NSUUID().UUIDString
node.setProp("propertyKey_1", propertyValue: "propertyValue_1" + randomString)
node.setProp("propertyKey_2", propertyValue: "propertyValue_2" + randomString)
theo.createNode(node, completionBlock: {(node, error) in
print("new node \(node)")
});
有标签
let node = Node()
let randomString: String = NSUUID().UUIDString
node.setProp("propertyKey_1", propertyValue: "propertyValue_1" + randomString)
node.setProp("propertyKey_2", propertyValue: "propertyValue_2" + randomString)
node.addLabel("customLabelForNode_" + randomString)
theo.createNode(node, completionBlock: {(node, error) in
print("new node \(node)")
});
或者
let node = Node()
let randomString: String = NSUUID().UUIDString
node.setProp("succesfullyAddNodeWithLabel_1", propertyValue: "succesfullyAddNodeWithLabel_1" + randomString)
node.setProp("succesfullyAddNodeWithLabel_2", propertyValue: "succesfullyAddNodeWithLabel_2" + randomString)
node.setProp("succesfullyAddNodeWithLabel_3", propertyValue: 123456)
node.addLabel("test_008_succesfullyAddNodeWithLabel_" + randomString)
theo.createNode(node, labels: node.labels, completionBlock: {(_, error) in
print("new node \(node)")
})
let updatedPropertiesDictionary: [String:String] = ["test_update_property_label_1": "test_update_property_lable_2"]
theo.updateNode(updateNode!, properties: updatedPropertiesDictionary,
completionBlock: {(node, error) in
})
theo.deleteNode("IDForDeletion", completionBlock: {error in
print("error \(error?.description)")
})
var relationship: Relationship = Relationship()
relationship.relate(parentNodeInstance, toNode: relatedNodeInstance, type: RelationshipType.KNOWS)
// setting properties is optional
relationship.setProp("my_relationship_property_name", propertyValue: "my_relationship_property_value")
theo.createRelationship(relationship, completionBlock: {(node, error) in
print("meta in success \(node!.meta) node \(node) error \(error)")
})
theo.fetchRelationshipsForNode("nodeIDWithRelationships", direction: RelationshipDirection.ALL, types: nil, completionBlock: {(relationships, error) in
if let foundRelationship: Relationship = relationships[0] as Relationship! {
if let relMeta: RelationshipMeta = foundRelationship.relationshipMeta {
relationshipIDToDelete = relMeta.relationshipID()
}
theo.deleteRelationship(relationshipIDToDelete!, completionBlock: {error in
})
}
})
let updatedProperties: Dictionary<String, AnyObject> = ["updatedRelationshipProperty" : "updatedRelationshipPropertyValue"]
theo.updateRelationship(foundRelationshipInstance, properties: updatedProperties, completionBlock: {(_, error) in
})
let createStatement: String = "CREATE ( bike:Bike { weight: 10 } ) CREATE ( frontWheel:Wheel { spokes: 3 } ) CREATE ( backWheel:Wheel { spokes: 32 } ) CREATE p1 = bike -[:HAS { position: 1 } ]-> frontWheel CREATE p2 = bike -[:HAS { position: 2 } ]-> backWheel RETURN bike, p1, p2"
let resultDataContents: Array<String> = ["row", "graph"]
let statement: Dictionary <String, AnyObject> = ["statement" : createStatement, "resultDataContents" : resultDataContents]
let statements: Array<Dictionary <String, AnyObject>> = [statement]
theo.executeTransaction(statements, completionBlock: {(response, error) in
print("response \(response) and error \(error?.description")
})
let theo: Client = Client(baseURL: configuration.host, user: configuration.username, pass: configuration.password)
let cyperQuery: String = "MATCH (u:User {username: {user} }) WITH u MATCH (u)-[:FOLLOWS*0..1]->(f) WITH DISTINCT f,u MATCH (f)-[:LASTPOST]-(lp)-[:NEXTPOST*0..3]-(p) RETURN p.contentId as contentId, p.title as title, p.tagstr as tagstr, p.timestamp as timestamp, p.url as url, f.username as username, f=u as owner"
let cyperParams: Dictionary<String, AnyObject> = ["user" : "ajordan"]
theo.executeCypher(cyperQuery, params: cyperParams, completionBlock: {(cypher, error) in
println("response from cyper \(cypher)")
})
有一个名为 TheoConfig.json.example
的文件,您应该将其复制到 TheoConfig.json
。您可以在该配置文件中添加您的 username
、password
和 baseUrl
,测试类将使用这些而不是需要修改任何 实际 类文件。TheoConfig.json
位于 .gitignore
中,因此您不必担心凭据被提交。
CMD-U