Click here to Skip to main content
15,860,972 members
Articles / Web Development / HTML

RaptorDB - The Document Store

Rate me:
Please Sign up or sign in to vote.
4.96/5 (278 votes)
24 Jul 2019CPOL86 min read 2.3M   16.3K   653  
NoSql, JSON based, Document store database with compiled .net map functions and automatic hybrid bitmap indexing and LINQ query filters (now with standalone Server mode, Backup and Active Restore, Transactions, Server side queries, MonoDroid support, HQ-Branch Replication, working in Linux, .net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace RaptorDB
{
    public static class RDBExtensions
    {
        /// <summary>
        /// For RaptorDB optimized range queries
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static bool Between<T>(this T obj, T from, T to)
        {
            return true;
        }

        /// <summary>
        /// For RaptorDB full text search queries
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="what"></param>
        /// <returns></returns>
        public static bool Contains(this string obj, string what)
        {
            return true;
        }
    }

    /// <summary>
    /// Used for normal string columns 
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class CaseInsensitiveAttribute : Attribute
    {
    }

    /// <summary>
    /// Used for the indexer -> hOOt full text indexing
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class FullTextAttribute : Attribute
    {
    }

    /// <summary>
    /// Used for declaring view extensions DLL's
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class RegisterViewAttribute : Attribute
    {
    }

    public interface IMapAPI
    {
        /// <summary>
        /// Log messages
        /// </summary>
        /// <param name="message"></param>
        void Log(string message);

        /// <summary>
        /// Query a view by it's name with a LINQ filter
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ViewName"></param>
        /// <param name="Filter"></param>
        /// <returns></returns>
        Result<object> Query<T>(string ViewName, Expression<Predicate<T>> Filter); // Query primary list

        /// <summary>
        /// Query a View with a LINQ filter with paging
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ViewName"></param>
        /// <param name="Filter"></param>
        /// <param name="start"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        Result<object> Query<T>(string ViewName, Expression<Predicate<T>> Filter, int start, int count); // Query primary list

        /// <summary>
        /// Query a view by it's type with a LINQ filter
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="View"></param>
        /// <param name="Filter"></param>
        /// <returns></returns>
        Result<object> Query<T>(Type View, Expression<Predicate<T>> Filter); //Query other views

        /// <summary>
        /// Query a View Type with a LINQ filter with paging
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="View"></param>
        /// <param name="Filter"></param>
        /// <param name="start"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        Result<object> Query<T>(Type View, Expression<Predicate<T>> Filter, int start, int count); //Query other views

        /// <summary>
        /// Count all data associated with the Documnet Type or the View Type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        int Count(Type type);

        /// <summary>
        /// Count all data associated with the Documnet Type or the View Type with a string filter
        /// </summary>
        /// <param name="viewname"></param>
        /// <returns></returns>
        int Count(string viewname);

        /// <summary>
        /// Count all data associated with the Documnet Type or the View Type with a LINQ filter
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <param name="Filter"></param>
        /// <returns></returns>
        int Count<T>(Type type, Expression<Predicate<T>> Filter);

        /// <summary>
        /// Count all data associated with View name and LINQ filter
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ViewName"></param>
        /// <param name="Filter"></param>
        /// <returns></returns>
        int Count<T>(string ViewName, Expression<Predicate<T>> Filter);

        /// <summary>
        /// Count all data associated with View name and string filter
        /// </summary>
        /// <param name="ViewName"></param>
        /// <param name="Filter"></param>
        /// <returns></returns>
        int Count(string ViewName, string Filter);

        /// <summary>
        /// Count all data associated with the Documnet Type or the View Type with a string filter
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <param name="Filter"></param>
        /// <returns></returns>
        int Count<T>(Type type, string Filter);

        /// <summary>
        /// Fetch a document by it's Guid
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        object Fetch(Guid guid);

        /// <summary>
        /// Emit values, the ordering must match the view schema
        /// </summary>
        /// <param name="docid"></param>
        /// <param name="data"></param>
        void Emit(Guid docid, params object[] data);

        /// <summary>
        /// Emits the object matching the view schema, you must make sure the object property names match the row schema
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="docid"></param>
        /// <param name="doc"></param>
        void EmitObject<T>(Guid docid, T doc);

        /// <summary>
        /// Roll back the transaction if the primary view is in transaction mode
        /// </summary>
        void RollBack();

        // new query model
        Result<T> Query<T>(Expression<Predicate<T>> Filter);
        Result<T> Query<T>(Expression<Predicate<T>> Filter, int start, int count);
        Result<T> Query<T>(string Filter);
        Result<T> Query<T>(string Filter, int start, int count);
        int Count<T>(Expression<Predicate<T>> Filter);
        //int Count<T>(string Filter);
    }

    public interface IDocStorage<T>
    {
        int RecordCount();

        byte[] Get(int rowid, out Guid docid, out bool isdeleted);

        bool Get(int rowid, out byte[] doc);

        bool Get(T key, out byte[] doc);
    }
}

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