Last active
August 29, 2015 14:09
-
-
Save mtranter/68db17c0fe777a080ea3 to your computer and use it in GitHub Desktop.
Possible New Cypher API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test | |
{ | |
static void Main() | |
{ | |
IStartClause<Person> startClause = null; | |
startClause | |
.Start(ctx => ctx.AtAnyNode(p => p)) | |
.Match(ctx => ctx.Node(p => p).Relates("has_job").To(p => p.Job)) | |
.Where(p => p.Name == "Mark" && p.Job.Name == "MGND") | |
.Returns(p => p); | |
// In theory, the above query could easily become... | |
startClause | |
.Where(p => p.Name == "Mark" && p.Job.Name == "MGND") | |
.Returns(p => p); | |
// Because the Start and Match clauses are redundant.. We can work them out from the model! | |
} | |
class Person | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public Job Job { get; set; } | |
} | |
class Job | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
} | |
} | |
class CypherContext | |
{ | |
} | |
interface IStartClause<TEntity> | |
{ | |
IMatchClause<TEntity> Start(Expression<Action<IStartQueryContext<TEntity>>> start); | |
} | |
interface IMatchClause<TEntity> | |
{ | |
IWhereClause<TEntity> Match(Expression<Action<IMatchQueryContext<TEntity>>> start); | |
} | |
interface IWhereClause<TEntity> | |
{ | |
IReturnClause<TEntity> Where(Expression<Func<TEntity, bool>> startAt); | |
} | |
interface IReturnClause<TEntity> | |
{ | |
IEnumerable<TProp> Returns<TProp>(Expression<Func<TEntity, TProp>> entity); | |
} | |
interface ICypherNodeRefence<TEntity> | |
{ | |
ICypherRelationshipRefence<TEntity> Relates(string relationship); | |
} | |
interface ICypherRelationshipRefence<TEntity> | |
{ | |
ICypherNodeRefence<TEntity> To<TProp>(Expression<Func<TEntity, TProp>> relatesTo); | |
} | |
interface IStartQueryContext<TEntity> | |
{ | |
IStartQueryContext<TEntity> AtAnyNode<TNode>(Expression<Func<TEntity, TNode>> startAt); | |
IStartQueryContext<TEntity> AtId<TNode>(Expression<Func<TEntity, TNode>> predicates, int id); | |
IStartQueryContext<TEntity> AtIndex(string index, params Expression<Func<TEntity, bool>>[] predicates); | |
} | |
interface IMatchQueryContext<TEntity> | |
{ | |
ICypherNodeRefence<TEntity> Node<TNode>(Expression<Func<TEntity, TNode>> startAt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment