Theo 5.2.0

Theo 5.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2020年7月
SPM支持 SPM

Niklas Saers 维护。



Theo 5.2.0

  • Niklas Saers 和 Cory Wiles

Thomas Anderson 是一位计算机程序员,他同时保持着作为“Neo”这个黑客的双重生活。 - Neo 和 Thomas 的组合

总结

Theo 是一个用 Swift 编写的开源框架,它提供了一个与 Neo4j 互动的接口。

特性

  • 节点和关系的基本 CRUD 操作
  • 事务语句执行
  • 支持 iOS、macOS 和 Linux

需求

  • iOS 10.0 或更高 / macOS 10.12 或更高 / Ubuntu Linux 14.04 或更高
  • 适用于 iOS 或 macOS 的 Xcode 8.3.2 或更高版本
  • Swift 3.1.1

反馈

因为这个框架是开源的,所以最好在 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 ‘Theoend

运行 pod install 以配置您的更新工作区。打开生成的 .xcworkspace,您的项目现在已准备好使用 Theo

运行 carthage update --platform iOS 以构建框架,并将构建的 Theo.framework 拖入您的 Xcode 项目中。

###git 子模块

  1. 将其添加为子模块到现有项目中。git submodule add [email protected]:GraphStory/neo4j-ios.git
  2. 打开 Theo 文件夹,并将 Theo.xcodeproj 拖入 Xcode 项目的文件导航器中。
  3. 在 Xcode 中,通过单击蓝色的项目图标并选择侧边栏中“目标”下的应用程序目标,转到目标配置窗口。
  4. 在窗口顶部的标签栏上,打开“构建阶段”面板。
  5. 展开“链接二进制与库”组,并添加 Theo.framework。
  6. 在面板的左上角单击加号按钮并选择“新复制文件阶段”。将此新阶段重命名为“复制框架”,设置“目标”为“框架”,并添加 Theo.framework。

使用

初始化

注意 - 主机名后请不要包含斜杠

示例: 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)")
})

通过 id 获取节点

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")
})

执行Cypher查询

        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。您可以在该配置文件中添加您的 usernamepasswordbaseUrl,测试类将使用这些而不是需要修改任何 实际 类文件。TheoConfig.json 位于 .gitignore 中,因此您不必担心凭据被提交。

执行

  • 选择单元测试目标
  • CMD-U

作者