Пример #1
0
        internal static string WhereSql(Query query)
        {
            SQLBuilder builder = new SQLBuilder();

            builder.AppendWhere();
            builder.Append(query.DirectoryId > 0, "and", "directory_id=@DirectoryId");
            builder.Append(!string.IsNullOrWhiteSpace(query.Name), "and", "api_name like '%" + query.Name + "%'");

            return builder.Sql();
        }
Пример #2
0
        internal static Tuple<string,dynamic> SelectByQuery(Query query)
        {
            string whereSql = WhereSql(query);
            string countSql = string.Join(" ", "select count(*) Count from register_apis", whereSql + ";");
            string dataSql = string.Join(" ", BaseSelectSql(), whereSql, string.Format("limit {0} offset {1};", query.PageSize, (query.PageIndex - 1) * query.PageSize));

            return new Tuple<string, dynamic>(countSql + dataSql, new
            {
                DirectoryId = query.DirectoryId
            });
        }
Пример #3
0
        public IEnumerable<Model.Api.Api> SelectByQuery(Query query, out int totalRows)
        {
            using (var conn = Database.Open())
            {
                var tuple = ApiSql.SelectByQuery(query);
                var reader = conn.QueryMultiple(tuple.Item1, (object)tuple.Item2);
                var count = reader.Read<object>().First() as IDictionary<string, object>;
                totalRows = Convert.ToInt32(count["Count"]);

                return reader.Read<Model.Api.Api>();
            }
        }