TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jul 2020 |
SPMSupports SPM | ✓ |
Maintained by Niklas Saers.
Thomas Anderson is a computer programmer who maintains a double life as "Neo" the hacker. - Combination of Neo and Thomas
Theo is an open-source framework written in Swift that provides an interface for interacting with Neo4j.
Because this framework is open source it is best for most situations to post on Stack Overflow and tag it Theo. If you do
find a bug please file an issue or issue a PR for any features or fixes.
You can install Theo in a number of ways
###Swift Package Manager
Add the following line to your Package dependencies array:
.Package(url: "https://github.com/GraphStory/neo4j-ios.git”, majorVersion: 3, minor: 0)
Run swift build
to build your project, now with Theo included and ready to be used from your source
###CococaPods
Add the following to your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘10.0’
use_frameworks!
target '<Your Target Name>' do
pod ‘Theo’
end
Run pod install
to configure your updated workspace. Open the .xcworkspace generated, your project is now ready to use Theo
Run carthage update --platform iOS
to build the framework and drag the built Theo.framework
into your Xcode project.
###git submodule
git submodule add [email protected]:GraphStory/neo4j-ios.git
PLEASE NOTE - DO NOT INCLUDE A TRAILING SLASH IN YOUR HOSTNAME
Example: http://www.hostname.com
not http://www.hostname.com/
Without authentication
let theo: Client = Client(baseURL: "hostname.com")
With authentication
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)")
})
Without Labels
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)")
});
With Labels
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)")
});
or
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)")
})
There is a file called, TheoConfig.json.example
which you should copy to TheoConfig.json
. You can add your username
, password
and baseUrl
to this config and the test classes use these instead of having to modify any actual class files. TheoConfig.json
is in the .gitignore
so you don't have to worry about creds being committed.
CMD-U