public IEnumerable <User> GetAllAuthors() { var relexParser = new RelexParser(); var relexQuery = "Users[*;Id asc]"; var q = relexParser.Parse(relexQuery); return(_DbNRecoAdapter.Select(q).ToList <User>()); }
public void test_RelexVar() { var relExParser = new RelexParser(); var cnd = relExParser.ParseCondition("\"hey:%{0}\":var = \"hey\" "); Assert.True(cnd is QConditionNode); Assert.True(((QConditionNode)cnd).LValue is QVar); ((QVar)((QConditionNode)cnd).LValue).Set("yeh"); Assert.Equal("\"%yeh\"=\"hey\"", new RelexBuilder().BuildRelex(cnd)); }
public void test_Parse() { var relExParser = new RelexParser(); // generate SQL by query var dbFactory = new TestRelExDbFactory(); var cmdGenerator = new DbCommandBuilder(dbFactory); for (int i = 0; i < oldRelExSamples.Length; i++) { string relEx = oldRelExSamples[i]; Query q = relExParser.Parse(relEx); IDbCommand cmd = cmdGenerator.GetSelectCommand(q); Assert.Equal(oldRelExCommandTexts[i], cmd.CommandText.Trim()); } for (int i = 0; i < relExSamples.Length; i++) { string relEx = relExSamples[i]; Query q = relExParser.Parse(relEx); IDbCommand cmd = cmdGenerator.GetSelectCommand(q); Assert.Equal(relExCommandTexts[i], cmd.CommandText.Trim()); } // test for named nodes string relexWithNamedNodes = @"users( (<idGroup> id=null and id!=null) and (<ageGroup> age>5 or age<2) and (<emptyGroup>) )[count(*)]"; Query qWithGroups = relExParser.Parse(relexWithNamedNodes); Assert.NotEqual(null, FindNodeByName(qWithGroups.Condition, "idGroup")); Assert.NotEqual(null, FindNodeByName(qWithGroups.Condition, "ageGroup")); Assert.NotEqual(null, FindNodeByName(qWithGroups.Condition, "emptyGroup")); // just a parse test for real complex relex string sss = "sourcename( ( ((\"False\"=\"True\") or (\"False\"=\"True\")) and \"contact-of\" in agent_to_agent_role( left_uid in agent_accounts(agent_accounts.id=\"\")[agent_id] and (right_uid=agent_institutions.id) )[role_uid] ) or ( ((agent_institutions.id in events( events.id in event_assignments( person_id in agent_accounts (agent_accounts.id=\"\")[agent_id] )[event_id] )[client_institution_id]) or (agent_institutions.id in events( events.id in event_assignments( person_id in agent_accounts (agent_accounts.id=\"\")[agent_id] )[event_id] )[supplier_institution_id])) and (\"False\"=\"True\") ) or ( (agent_institutions.id in agent_to_agent_role( (left_uid in agent_to_agent_role( left_uid in agent_accounts(agent_accounts.id=\"\")[agent_id] and role_uid='contact-of' )[right_uid]) and role_uid='supplier-of')[right_uid] ) or (agent_institutions.id in events( events.supplier_institution_id in agent_to_agent_role( (agent_to_agent_role.role_uid='contact-of') and (agent_to_agent_role.left_uid in agent_accounts(agent_accounts.id=\"\")[agent_id]) )[agent_to_agent_role.right_uid] )[events.client_institution_id]) or (agent_institutions.id in events( events.client_institution_id in agent_to_agent_role( (agent_to_agent_role.role_uid='contact-of') and (agent_to_agent_role.left_uid in agent_accounts(agent_accounts.id=\"\")[agent_id]) )[agent_to_agent_role.right_uid] )[events.supplier_institution_id]) ) or (\"False\"=\"True\") or ( (\"False\"=\"True\") and (agent_institutions.id in agent_to_agent_role( role_uid='supplier-of' and right_uid = \"\" )[left_uid]) ) or (\"False\"=\"True\") )[*]"; relExParser.Parse(sss); var complexSortAndFields = "users.u( u.id=1 )[\"name+','\";id asc,id desc,\"sum(id)\"]"; var complexQ = relExParser.Parse(complexSortAndFields); Assert.Equal(1, complexQ.Fields.Length); Assert.Equal(3, complexQ.Sort.Length); Assert.Throws <RelexParseException>(() => { relExParser.Parse("users[id"); }); }
public void test_RelexParseSpeed() { var relExParser = new RelexParser(); var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); var iterations = 1000; for (int iter = 0; iter < iterations; iter++) { for (int i = 0; i < relExSamples.Length; i++) { string relEx = relExSamples[i]; Query q = relExParser.Parse(relEx); } } stopwatch.Stop(); Console.WriteLine("Speedtest for relex parse ({1} times): {0}", stopwatch.Elapsed, iterations * relExSamples.Length); }