Click here to Skip to main content
15,860,859 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.Diagnostics;
using System.Collections;
using System.IO;
using System.Text;
using System.Threading;
using RaptorDB;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Reflection;
using RaptorDB.Views;
using System.Linq.Expressions;
using System.Linq;
using System.Collections.ObjectModel;
using System.Dynamic;
using RaptorDB.Common;

namespace testing
{
    public class program
    {
        static RaptorDBServer server;
        public static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            server = new RaptorDBServer(90, @"..\..\..\RaptorDBdata");
            //RaptorDBClient client = new RaptorDBClient("127.0.0.1", 90, "admin", "admin");
            //var r = client.Query("salesinvoice", "serial<100");
            Console.WriteLine("Server started on port 90");
            Console.WriteLine("Press Enter to exit...");
            Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
            
            Console.ReadLine();
            server.Shutdown();
            return;
            /*
            RaptorDB.RaptorDB rap = RaptorDB.RaptorDB.Open(@"..\..\..\RaptorDBdata");

            rap.RegisterView(new SalesInvoiceView());
            rap.RegisterView(new SalesItemRowsView());
            rap.RegisterView(new newview());
            bool end = false;

            Console.WriteLine("Press (P)redifined query, (I)nsert 100,000 docs, (S)tring query, (Q)uit");

        redo:
            ConsoleKey key = Console.ReadKey().Key;
            Console.WriteLine();

            switch (key)
            {
                case ConsoleKey.P:
                    predefinedquery(rap);
                    break;
                case ConsoleKey.I:
                    insertdata(rap);
                    break;
                case ConsoleKey.S:
                    stringquery(rap);
                    break;
                case ConsoleKey.Q:
                    end = true;
                    break;
                default:
                    Console.WriteLine("Press (P)redifined query, (I)nsert 100,000 docs, (S)tring query, (Q)uit");
                    break;
            }
            if (!end)
                goto redo;
            rap.Shutdown();
        }

        private static void stringquery(RaptorDB.RaptorDB rap)
        {
            Console.WriteLine("Enter you query in the following format :  viewname , query");
            string[] s = Console.ReadLine().Split(',');
            DateTime dt = FastDateTime.Now;
            try
            {
                var q = rap.Query(s[0].Trim(), s[1].Trim());
                Console.WriteLine("query time = " + FastDateTime.Now.Subtract(dt).TotalSeconds);
                Console.WriteLine("query count = " + q.Count);
                Console.WriteLine();
            }
            catch { Console.WriteLine("error in query."); }
        }

        private static void predefinedquery(RaptorDB.RaptorDB rap)
        {
            DateTime dt = FastDateTime.Now;
            int j = 100;
            var q = rap.Query(typeof(SalesInvoice), (SalesInvoice l) => (l.Serial == j));
            Console.WriteLine("query SalesInvoice time = " + FastDateTime.Now.Subtract(dt).TotalSeconds);
            Console.WriteLine("query count = " + q.Count);
                
            q = rap.Query(typeof(SalesItemRowsView), (LineItem l) => (l.Product == "prod 1" || l.Product == "prod 3"));
            
            // grouping
            List<SalesItemRowsView.RowSchema> list = q.Rows.Cast<SalesItemRowsView.RowSchema>().ToList();
            var e = from item in list group item by item.Product into grouped 
                    select new { Product = grouped.Key, 
                                 TotalPrice = grouped.Sum(product => product.Price),
                                 TotalQTY = grouped.Sum(product => product.QTY)
                    };

            //string str = fastJSON.JSON.Instance.ToJSON(e.ToList(), new fastJSON.JSONParamters { EnableAnonymousTypes = true });

            Console.WriteLine("query lineitems time = " + FastDateTime.Now.Subtract(dt).TotalSeconds);
            Console.WriteLine("query count = " + q.Count);
            Console.WriteLine();
        }

        private static void insertdata(RaptorDB.RaptorDB rap)
        {
            DateTime dt = FastDateTime.Now;

            for (int i = 0; i < 100000; i++)
            {
                var inv = new SalesInvoice()
                {
                    Date = FastDateTime.Now,
                    Serial = i % 10000,
                    CustomerName = "me " + i % 10,
                    Status = (byte)(i % 4),
                    Address = "df asd sdf asdf asdf"
                };
                inv.Items = new List<LineItem>();
                for (int k = 0; k < 5; k++)
                    inv.Items.Add(new LineItem() { Product = "prod " + k, Discount = 0, Price = 10 + k, QTY = 1 + k });
                if (i % 5000 == 0)
                    Console.Write(".");
                rap.Save(inv.ID, inv);
            }
            Console.WriteLine();
            Console.WriteLine("insert time secs = " + FastDateTime.Now.Subtract(dt).TotalSeconds);
             */
        }

        static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
        {
            Console.WriteLine("Shutting down...");
            server.Shutdown();
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            File.WriteAllText("error.txt", "" + e.ExceptionObject);
        }
    }
}

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