Click here to Skip to main content
15,861,168 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.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using RaptorDB;
using RaptorDB.Common;
using SampleViews;

namespace datagridbinding
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        IRaptorDB rap;

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.DoubleBuffered(true);
            Form2 f = new Form2();
            if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                rap = f._rap;

                Query();
            }
        }

        void TextBox1KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
                Query();
        }

        private void Query()
        {
            string[] s = textBox1.Text.Split(',');

            try
            {
                DateTime dt = FastDateTime.Now;
                var q = rap.Query(s[0].Trim(), s[1].Trim());
                toolStripStatusLabel2.Text = "Query time (sec) = " + FastDateTime.Now.Subtract(dt).TotalSeconds;
                dataGridView1.DataSource = q.Rows;
                toolStripStatusLabel1.Text = "Count = " + q.Count.ToString("#,0");
            }
            catch { }
        }

        private void sumQueryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DateTime dt = FastDateTime.Now;
            var q = rap.Query(typeof(SalesItemRowsView), (LineItem l) => (l.Product == "prod 1" || l.Product == "prod 3"));

            List<SalesItemRowsView.RowSchema> list = q.Rows.Cast<SalesItemRowsView.RowSchema>().ToList();
            var res = 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)
                      };

            var reslist = res.ToList();
            dataGridView1.DataSource = reslist;
            toolStripStatusLabel2.Text = "Query time (sec) = " + FastDateTime.Now.Subtract(dt).TotalSeconds;
            toolStripStatusLabel1.Text = "Count = " + q.Count.ToString("#,0");
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rap != null)
                rap.Shutdown();
            this.Close();
        }

        private object _lock = new object();
        private void insert100000DocumentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lock (_lock)
            {
                DialogResult dr = MessageBox.Show("Do you want to insert?", "Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2);
                if (dr == System.Windows.Forms.DialogResult.Cancel)
                    return;
                toolStripProgressBar1.Value = 0;
                DateTime dt = FastDateTime.Now;
                int count = 100000;
                int step = 5000;
                toolStripProgressBar1.Maximum = (count / step) + 1;

                for (int i = 0; i < count; 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 % step == 0)
                        toolStripProgressBar1.Value++;
                    rap.Save(inv.ID, inv);
                }
                MessageBox.Show("Insert done in (sec) : " + FastDateTime.Now.Subtract(dt).TotalSeconds);
                toolStripProgressBar1.Value = 0;
            }
        }

        private void backupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool b = rap.Backup();
            MessageBox.Show("Backup done");
        }

        private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
        {
            rap.Restore();
        }
        public class objclass
        {
            public string val;
        }
        string prod3 = "prod 3";
        private void serverSideSumQueryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string prod1 = "prod 1";
            objclass c = new objclass() { val = "prod 1" };
            DateTime dt = FastDateTime.Now;
            //var q = rap.Query(typeof(SalesItemRowsView), (LineItem l) => (l.Product == prod1 || l.Product == prod3));

            var qq = rap.ServerSide(Views.ServerSide.Sum_Products_based_on_filter,
                //"product = \"prod 1\""
                (LineItem l) => (l.Product == c.val || l.Product == prod3)
                ).ToList();
            dataGridView1.DataSource = qq;
            toolStripStatusLabel2.Text = "Query time (sec) = " + FastDateTime.Now.Subtract(dt).TotalSeconds;
            toolStripStatusLabel1.Text = "Count = " + qq.Count.ToString("#,0");
        }
    }
}

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