Click here to Skip to main content
15,885,985 members
Articles / Web Development

RaptorDB REST

Rate me:
Please Sign up or sign in to vote.
4.92/5 (11 votes)
5 Dec 2013CPOL10 min read 36K   1K   29  
A REST web interface for RaptorDB the document database
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace RaptorDB.Views
{
    internal class apimapper : IMapAPI
    {
        public apimapper(ViewManager man)
        {
            _viewmanager = man;
        }

        ViewManager _viewmanager;
        private ILog _log = LogManager.GetLogger(typeof(apimapper));
        internal Dictionary<Guid, List<object[]>> emit = new Dictionary<Guid, List<object[]>>();
        internal Dictionary<Guid, List<object>> emitobj = new Dictionary<Guid, List<object>>();
        internal bool _RollBack = false;

        public void Log(string message)
        {
            _log.Debug(message);
        }

        //public Result<object> Query<T>(string ViewName, Expression<Predicate<T>> Filter)
        //{
        //    return _viewmanager.Query<T>(ViewName, Filter, 0, -1);
        //}

        //public Result<object> Query<T>(Type View, Expression<Predicate<T>> Filter)
        //{
        //    return _viewmanager.Query(View, Filter, 0, -1);
        //}

        public object Fetch(Guid guid)
        {
            return _viewmanager.Fetch(guid);
        }

        public void Emit(Guid docid, params object[] data)
        {
            if (data == null)
                return;
            List<object[]> d = null;
            if (emit.Count == 0)
            {
                d = new List<object[]>();
                d.Add(data);
                emit.Add(docid, d);
            }
            else
            {
                if (emit.TryGetValue(docid, out d))
                {
                    d.Add(data);
                }
                else
                {
                    d = new List<object[]>();
                    d.Add(data);
                    emit.Add(docid, d);
                }
            }
        }

        public void EmitObject<T>(Guid docid, T doc)
        {
            if (doc == null)
                return;
            List<object> d = null;
            if (emitobj.Count == 0)
            {
                d = new List<object>();
                d.Add(doc);
                emitobj.Add(docid, d);
            }
            else
            {
                if (emitobj.TryGetValue(docid, out d))
                {
                    d.Add(doc);
                }
                else
                {
                    d = new List<object>();
                    d.Add(doc);
                    emitobj.Add(docid, d);
                }
            }
        }

        public void RollBack()
        {
            _RollBack = true;
        }


        //public Result<object> Query<T>(string ViewName, Expression<Predicate<T>> Filter, int start, int count)
        //{
        //    return _viewmanager.Query<T>(ViewName, Filter, start, count);
        //}

        //public Result<object> Query<T>(Type View, Expression<Predicate<T>> Filter, int start, int count)
        //{
        //    return _viewmanager.Query<T>(View, Filter, start, count);
        //}

        //public int Count(Type type)
        //{
        //    return _viewmanager.Count(type, "");
        //}

        public int Count(string viewname)
        {
            return _viewmanager.Count(viewname, "");
        }

        //public int Count<T>(Type type, Expression<Predicate<T>> Filter)
        //{
        //    return _viewmanager.Count(type, Filter);
        //}

        //public int Count<T>(string ViewName, Expression<Predicate<T>> Filter)
        //{
        //    return _viewmanager.Count(ViewName, Filter);
        //}

        public int Count(string ViewName, string Filter)
        {
            return _viewmanager.Count(ViewName, Filter);
        }

        //public int Count<T>(Type type, string Filter)
        //{
        //    return _viewmanager.Count(type, Filter);
        //}

        public Result<T> Query<T>(Expression<Predicate<T>> Filter)
        {
            return _viewmanager.Query<T>(Filter, 0, -1);
        }

        public Result<T> Query<T>(Expression<Predicate<T>> Filter, int start, int count)
        {
            return _viewmanager.Query<T>(Filter, start, count);
        }

        public Result<T> Query<T>(string Filter)
        {
            return _viewmanager.Query<T>(Filter, 0, -1);
        }

        public Result<T> Query<T>(string Filter, int start, int count)
        {
            return _viewmanager.Query<T>(Filter, start, count);
        }

        public int Count<T>(Expression<Predicate<T>> Filter)
        {
            return _viewmanager.Count<T>(Filter);
        }

        //public int Count<T>(string Filter)
        //{
        //    return _viewmanager.Count<T>(Filter);
        //}
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect -
United Kingdom United Kingdom
Mehdi first started programming when he was 8 on BBC+128k machine in 6512 processor language, after various hardware and software changes he eventually came across .net and c# which he has been using since v1.0.
He is formally educated as a system analyst Industrial engineer, but his programming passion continues.

* Mehdi is the 5th person to get 6 out of 7 Platinum's on Code-Project (13th Jan'12)
* Mehdi is the 3rd person to get 7 out of 7 Platinum's on Code-Project (26th Aug'16)

Comments and Discussions