Click here to Skip to main content
15,879,535 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.Xml.Serialization;

namespace RaptorDB.Views
{
    internal class ViewRowDefinition
    {
        public ViewRowDefinition()
        {
            Columns = new List<KeyValuePair<string, Type>>();
        }
        public string Name { get; set; }
        internal List<KeyValuePair<string, Type>> Columns { get; set; }

        public void Add(string name, Type type)
        {
            Columns.Add(new KeyValuePair<string, Type>( name, type));
        }
    }

    public abstract class ViewBase
    {
        //public Guid DocID { get; set; }
        /// <summary>
        /// Name of the view will be used for foldernames and filename and generated code
        /// </summary>
        public string Name { get; set;}
        /// <summary>
        /// A text for describing this views purpose for other developers 
        /// </summary>
        public string Description { get; set; }

        ///// <summary>
        ///// C# code for the mapper function
        ///// </summary>
        //public string MapFunctionCode { get; set; }

        /// <summary>
        /// Column definitions for the view storage 
        /// </summary>
        public Type Schema { get; set; }

        internal ViewRowDefinition SchemaColumns { get; set; }

        /// <summary>
        /// A list of Types that this view responds to (inheiratance is supported)
        /// Use AddFireOnTypes() to add to this list
        /// </summary>
        public List<string> FireOnTypes { get; set; }

        ///// <summary>
        ///// List of Views used for code generation in the mapper function
        ///// </summary>
        //public List<ViewRowDefinition> ViewsUsed { get; set; }

        /// <summary>
        /// Is this the primary list and will be populated synchronously
        /// </summary>
        public bool isPrimaryList { get; set; }

        /// <summary>
        /// Is this view active and will recieve data
        /// </summary>
        public bool isActive { get; set; }

        /// <summary>
        /// Delete items on DocID before inserting new rows (default = true)
        /// </summary>
        public bool DeleteBeforeInsert { get; set; }

        ///// <summary>
        ///// 
        ///// </summary>
        //public bool RebuildIndexesOnSchemaChange { get; set; }

        /// <summary>
        /// Index in the background : better performance but reads might not have all the data
        /// </summary>
        public bool BackgroundIndexing { get; set; }

        /// <summary>
        /// Fire the mapper on these types
        /// </summary>
        /// <param name="type"></param>
        public void AddFireOnTypes(Type type)
        {
            FireOnTypes.Add(type.AssemblyQualifiedName);
        }
    }


    public class View<T> : ViewBase
    {
        public delegate void MapFunctionDelgate<V>(IMapAPI api, Guid docid, V doc);
        public View()
        {
            //DocID = Guid.NewGuid();
            isActive = true;
            FireOnTypes = new List<string>();
            DeleteBeforeInsert = true;
            BackgroundIndexing = true;
        }

        /// <summary>
        /// Inline delegate for the mapper function used for quick applications 
        /// </summary>
        [XmlIgnore]
        public MapFunctionDelgate<T> Mapper { get; set; }

        public Result Verify()
        {
            if (Name == null || Name == "") return new Result(false, new Exception("Name must be given"));
            if (Schema == null) return new Result(false, new Exception("Schema must be defined"));
            if (Mapper == null) return new Result(false, new Exception("A map function must be defined"));
            if (FireOnTypes.Count == 0) return new Result(false, new Exception("No types have been defined to fire on"));
            // FIX : add more verifications
            return new Result(true);
        }
    }
}

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