private static void ComplexQuery(Siaqodb siaqodb) { IBucket bucket = siaqodb.Documents["invoices"]; Invoice invoice = BuildInvoice(); //insert invoice with tags with Document way Document doc = new Document(); doc.Key = invoice.Id; doc.SetContent <Invoice>(invoice); doc.SetTag <int>("year", invoice.InvoiceDate.Year); //this tag will be automatically indexed doc.SetTag <string>("customer", invoice.CustomerCode); //this tag will be automatically indexed bucket.Store(doc); //register key convention, so we can work directly with POCO SiaqodbConfigurator.RegisterKeyConvention <Invoice>(a => a.Id); Invoice invoice2 = BuildInvoice(); //insert invoice with tags in POCO way - invoice is tagged with 2 tags: year and customer bucket.Store(invoice2, new { year = invoice2.InvoiceDate.Year, customer = invoice2.CustomerCode }); //query with Fluent API Query query = new Query(); query.WhereGreaterThanOrEqual("year", invoice.InvoiceDate.Year).WhereEqual("customer", invoice.CustomerCode); //execute query var docs = bucket.Find(query); foreach (Document d in docs) { Invoice inv = d.GetContent <Invoice>(); Console.WriteLine("Invoice with Id:" + d.Key + " loaded by complex query."); } //run same query using LINQ: var docsLINQ = from Document d in bucket where d.GetTag <int>("year") >= invoice.InvoiceDate.Year && d.GetTag <string>("customer") == invoice.CustomerCode select d; foreach (Document d in docsLINQ) { Invoice inv = d.GetContent <Invoice>(); Console.WriteLine("Invoice with Id:" + d.Key + " loaded by LINQ complex query"); } }
private static void SimpleQuery(Siaqodb siaqodb) { IBucket bucket = siaqodb.Documents["invoices"]; Invoice invoice = BuildInvoice(); //insert Document doc = new Document(); doc.Key = invoice.Id; doc.SetContent <Invoice>(invoice); doc.SetTag <int>("year", invoice.InvoiceDate.Year);//this tag will be automatically indexed bucket.Store(doc); Query query = new Query(); query.WhereEqual("year", invoice.InvoiceDate.Year); //execute query var docs = bucket.Find(query); foreach (Document d in docs) { Invoice inv = d.GetContent <Invoice>(); Console.WriteLine("Invoice with Id:" + d.Key + " loaded by query"); } //run same query using LINQ: var docsLINQ = from Document d in bucket where d.GetTag <int>("year") == invoice.InvoiceDate.Year select d; foreach (Document d in docsLINQ) { Invoice inv = d.GetContent <Invoice>(); Console.WriteLine("Invoice with Id:" + d.Key + " loaded by LINQ query"); } }
static void Main(string[] args) { Random rnd = new Random(); Sqo.SiaqodbConfigurator.SetLicense(@"your license"); SiaqodbConfigurator.SetDocumentSerializer(new MyJsonSerializer()); SiaqodbConfigurator.SetSyncableBucket("invoices_encrypted", true); //IQrypt settings IQryptSiaqodbConfigurator.SetEncryptionChiper(IQrypt.Cipher.AES256, "myencryption_key"); IQryptSiaqodbConfigurator.EncryptDocumentContent("invoices_encrypted"); IQryptSiaqodbConfigurator.EncryptTag("customer_code", IQrypt.EncryptionType.DET, typeof(string)); try { using (Siaqodb siaqodb = new Siaqodb(@"c:\DATA\")) { IBucket bucket = siaqodb.Documents["invoices_encrypted"]; Invoice inv = new Invoice { CustomerName = "My Company", InvoiceDate = DateTime.Now, Total = 2390 }; IQryptDocument document = new IQryptDocument(); document.Key = "InVoice-" + rnd.Next(); document.SetContent <Invoice>(inv); string tagVal = "CU2323" + rnd.Next(); document.SetTag("customer_code", tagVal); bucket.Store(document); // let's run a query Query query = new Query(); query.IQryptWhereEqual("customer_code", tagVal); var q = bucket.Find(query); foreach (Document o in q) { if (o.GetTag <string>("customer_code") == tagVal) { Console.WriteLine("Query over encrypted data run!"); } } using (SiaqodbSync syncContext = new SiaqodbSync("http://localhost:11735/v0/", "97c7835153fd66617fad7b43f4000647", "4362kljh63k4599hhgm")) { //pull(which will trigger also push) will upload and than download changes to/from cloud/server PullResult syncResult = syncContext.Pull(bucket); if (syncResult.Error != null) { Console.WriteLine("Error downloading changes:" + syncResult.Error.Message); } else { Console.WriteLine("Sync finished!"); Console.WriteLine("Uploaded:" + syncResult.PushResult.SyncStatistics.TotalUploads + " documents!"); Console.WriteLine("Downloaded:" + syncResult.SyncStatistics.TotalDownloads + " documents!"); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }