接着上一篇这里罗列下STSDB的一般性使用
以下内容基于stsdb4.dll(4.0.3.0版本)库(百度分享资源:http://pan.baidu.com/s/1jGxHE3k),截止本文发布,官方最新版本是4.0.5.0,官方地址:http://stsdb.com/
?
using System;
using System.Collections.Generic;
namespace STSDB
{
[Serializable]
public class TStudent
{
public TStudent()
{
}
public string Name { get; set; }
public int Age { get; set; }
public int GroupNumber { get; set; }
public List CourseList { get; set; }
}
}
using System;
namespace STSDB
{
[Serializable]
public class TCourse
{
public string CourseName { get; set; }
public string Teacher { get; set; }
public int Score { get; set; }
}
}
演示代码:
/*
* 1. STSdb 4.0 是一个开源的NoSQL 数据库和虚拟文件系统,支持实时索引,完全用c#开发的。
* 引擎原理基于WaterfallTree(瀑布树)数据结构搭建
*
*
* 2.特性
* 支持几十亿级别的数据存取
* 支持TB级别文件大小
* 实时索引
* 内置压缩
* 内置序列化
* 支持稀疏分散的文件(byte[])
* 存储内存可控
* 支持多线程,且线程安全
* Storage engine instance is thread-safe. Creating (opening) XTable and XFile instances in one storage engine from
different threads is thread-safe.
XTable and XFile instances are also thread-safe. Manipulating different XTable/XFile instances from different threads
is thread-safe.
*
* 3.缺点
* 不支持事务
* 同时处理所有打开的表
*
* 支持多种情况下的数据引擎连接
IStorageEngine engine = STSdb.FromMemory(); //从内存中读取
IStorageEngine engine = STSdb.FromStream(stream); //从数据流中读取
IStorageEngine engine = STSdb.FromHeap(heap); //从堆栈中读取
IStorageEngine engine = STSdb.FromNetwork(host, port); //从远程地址读取
*
*
*/
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace STSDB
{
using Newtonsoft.Json;
using STSdb4.Data;
using STSdb4.Database;
using STSdb4.Storage;
using STSdb4.WaterfallTree;
using STSdb4.Remote.Heap;
class Program
{
static void Main(string[] args)
{
ExecuteCode(WriteData);
ExecuteCode(ReadData);
//ExecuteCode(DatabaseSchemeInfo);
//ExecuteCode(ReadItem);
//ExecuteCode(DeleteItems);
//ExecuteCode(ReadItem);
//ExecuteCode(GetRecord);
//ExecuteCode(PageRecord);
//ExecuteCode(Others);
//ExecuteCode(ReNameTable);
//ExecuteCode(ExistsTable);
//ExecuteCode(DeleteTable);
//ExecuteCode(ExistsTable);
#region test
//bool quit = false;
//while (!quit)
//{
// Console.Write("get item data: ");
// string demo = Console.ReadLine();
// switch (demo)
// {
// case "Y":
// break;
// case "Q":
// quit = true;
// break;
// default:
// Console.WriteLine("Choose a Word between Y and Q(to quit)");
// break;
// }
//}
#endregion
Console.ReadKey();
}
/// 执行方法
static void ExecuteCode(Action act)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
act();
stopwatch.Stop();
TimeSpan timespan = stopwatch.Elapsed;
Console.WriteLine("运行{0}秒", timespan.TotalSeconds);
}
///
/// 数据库名
///
/// 文件名和扩展名不限制
protected static string DataBase = "ClassDB.db";
///
/// 学生表名
///
protected static string TableName = "tb_student";
///
/// 【新】学生表名
///
protected static string NewTableName = "new_tb_student";
///
/// XFile
///
protected static string XFileName = "tb_file";
#region 基本操作
///
/// 创建库,写入数据
///
static void WriteData()
{
/*
* ①:没有数据库会自动创建的,默认目录和应用程序目录一致;
* ②:打开表,Key支持组合结构 => OpenXTable
*/
using (IStorag