Exemple #1
0
        public void TestSqlBuilder()
        {
            DataService.ConnectionString = "test.sqlite";
            DataService.Initialize(true);

            using (var db = DataService.Connect())
            {
                string releaseValue = "v3.8";
                SqlBuilder sb = new SqlBuilder();
                sb.Select("*");
                sb.Select("u1.Email AS AssignedToUserEmail, u1.UserName AS AssignedToUserName");
                sb.Select("u2.Email AS CreatedByUserEmail, u2.UserName AS CreatedByUserName");
                sb.Join(" User AS u1 ON Issue.AssignedToUserId=u1.Id");
                sb.Join(" User AS u2 ON Issue.CreatedByUserId=u2.Id");
                sb.Where("Release=@a", new { a = releaseValue });
                sb.Where("Votes>@b", new { b = 3});
                sb.OrderBy("Issue.Id");

                var t = new SqlBuilder.Template(sb, @"SELECT /**select**/ FROM Issue /**join**/ /**leftjoin**/ /**where**/ /**orderby**/", null);
                var iss = db.Query<IssueViewModel>(t.RawSql, t.Parameters);
                string sql = db.GetLastSql();
                Assert.NotEmpty(iss);
                Assert.Equal("*****@*****.**", iss[0].AssignedToUserEmail);
                Assert.Equal("*****@*****.**", iss[0].CreatedByUserEmail);
                Assert.Equal("This is the title.", iss[0].Title);

                //var jsb = new JoinSqlBuilder<CompleteIssue, Issue>();
                //jsb = jsb.Join<Issue, User>(i => i.AssignedToUserId, u => u.Id)
                //         .Join<Issue, User>(i => i.CreatedByUserId, x => x.Id)
                //         .Where<Issue>(i => i.Release == releaseValue);
                //string foo = jsb.ToSql();
                //var issues = db.Query<CompleteIssue>(foo);
                //string sql2 = db.GetLastSql();
                //Assert.NotEmpty(issues);
            }
        }
Exemple #2
0
 private static void ProcessSort(QuerySortColumn sort, SqlBuilder sql, Dictionary<string, object> parameters)
 {
     string column;
     if (AllowedColumns.TryGetValue(sort.Column, out column))
     {
         sql.OrderBy(column + (sort.Direction == QuerySortDirection.Descending ? " DESC" : String.Empty));
     }
 }