using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RaptorDB
{
public interface IRaptorDB
{
List<object> Query(string viewname, string filter, int start, int count);
//List<T> Query<T>(string viewname, string filter, int start, int count);
bool Save(object data);
object Fetch(Guid docid);
//T Fetch<T>(Guid docid);
void Configure(object configsettings);
void SetDocumentIDProperty(Type type, string IDproperty);
object GetView(string viewname);
void RegisterPrimaryView(Type type, string viewname);
}
public interface IMapApi
{
void Log(string message);
List<object[]> Query(string viewname, string filter, int start, int count);
object Fetch(Guid docid);
}
public class someview
{
}
// main object
public class dataobject
{
public Guid weirdid { get; set; }
}
// list for databject
public class dataview
{
public Guid docid { get; set; }
// other columns from map function
}
public class test
{
IRaptorDB _db;
public void something()
{
Guid g = Guid.NewGuid();
// guid property to use for docid, default if not defined = docid | id | guid --> error if not found or not guid
_db.SetDocumentIDProperty(typeof(dataobject), "weirdid");
dataobject d = new dataobject();
// set properties
// save document
_db.Save(d);
// get the data
dataobject dd = (dataobject)_db.Fetch(g);
//dd = _db.Fetch<dataobject>(g);
List<object> list = _db.Query("customers", "code > 1000 and city='here'", 0, -1); // all data
//List<dataview> dlist = _db.Query<dataview>("datalist", "date between ('2000/01/01' , '2001/01/31') ", 100, 10);
}
List<object[]> emitted = new List<object[]>();
public void emit(Guid docid, int i, string name, bool disable)
{
object[] data = new object[4];
data[0] = docid;
data[1] = i;
data[2] = name;
data[3] = disable;
emitted.Add(data);
}
public void map(dataobject input, IMapApi api)
{
api.Log("starting");
emit(input.weirdid, 10, "me", true);
object somedoc = api.Fetch(Guid.NewGuid());
dataobject dobj = (dataobject )api.Fetch(Guid.NewGuid());
List<object[]> inventory = api.Query("inventoryview", "productcode = '1234' and qty>100", 0, -1);
emit(input.weirdid, 11, "you", true);
emit(input.weirdid, 12, "dupree", false);
}
}
}