绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
STSdb4
2022-04-14 15:42:20

STSdb4


1.打开文件并建一个简单的表格:
using (IStorageEngine engine = STSdb.FromFile("test.stsdb4"))
{
var table = engine.OpenXTable<int, Tick>("table");
for (int i = 0; i < 1000000; i++)
{
table[i] = new Tick();
}
engine.Commit();
}

从表格中读取:
using (IStorageEngine engine = STSdb.FromFile("test.stsdb4"))
{
var table = engine.OpenXTable<int, Tick>("table");
foreach (var row in table) //table.Forward(), table.Backward()
{
Console.WriteLine("{0} {1}", row.Key, row.Value);
}
}

key也可以自己写一个类key,然后:
var table2 = engine.OpenXTable <Key, Tick>("table2");

通过该属性看引擎实例:
IDescriptor descriptor = engine["table"];

删除table:
engine.Delete("table");

重命名table:
engine.Rename("table", "table_NewName");

table是否存在:
bool exists = engine.Exists("table");

e里面有多少table:
int tablesCount = engine.Count;

engine提供的接口:
public interface IStorageEngine : IEnumerable<IDescriptor>, IDisposable
{
ITable<IData, IData> OpenXTablePortable(string name, DataType keyDataType, DataType recordDataType);
ITable<TKey, TRecord> OpenXTablePortable<TKey, TRecord>(string name, DataType keyDataType, DataType recordDataType, ITransformer<TKey, IData> keyTransformer, ITransformer<TRecord, IData> recordTransformer);
ITable<TKey, TRecord> OpenXTablePortable<TKey, TRecord>(string name);
ITable<TKey, TRecord> OpenXTable<TKey, TRecord>(string name);
XFile OpenXFile(string name);
IDescriptor this[string name] { get; }
IDescriptor Find(long id);
void Delete(string name);
void Rename(string name, string newName);
bool Exists(string name);
int Count { get; }
int CacheSize { get; set; }
IHeap Heap { get; }
void Commit();
void Close();
}

匿名类型:
ITable<TKey, TRecord> OpenXTablePortable<TKey, TRecord>(string name);

已知类型
ITable<TKey, TRecord> OpenXTable<TKey, TRecord>(string name);


打开的table,则可以当成简单的集合:
table[key] = record;
table.Delete(key);
if (table.Exists(key))
{
}
foreach (var kv in table)
{
}
foreach (var kv in table.Forward(fromKey, toKey)) //table.Backward()
{
}

引擎的接口:
IDescriptor this[string name] { get; }
IDescriptor Find(long id);
void Delete(string name);
void Rename(string name, string newName);
bool Exists(string name);
int Count { get; }
int CacheSize { get; set; }

引擎大小:
long databaseSize = engine.Size;

table、file的接口:
public interface IDescriptor
{
long ID { get; }
string Name { get; }
int StructureType { get; }
DataType KeyDataType { get; }
Type KeyType { get; set; }
DataType RecordDataType { get; }
Type RecordType { get; set; }
IComparer<IData> KeyComparer { get; set; }
IEqualityComparer<IData> KeyEqualityComparer { get; set; }
IPersist<IData> KeyPersist { get; set; }
IPersist<IData> RecordPersist { get; set; }
IIndexerPersist<IData> KeyIndexerPersist { get; set; }
IIndexerPersist<IData> RecordIndexerPersist { get; set; }
DateTime CreateTime { get; }
DateTime ModifiedTime { get; }
DateTime AccessTime { get; }
byte[] Tag { get; set; }
}
分享好友

分享这个小栈给你的朋友们,一起进步吧。

STSdb
创建时间:2022-04-14 10:53:57
STSdb
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • LCR_
    专家
戳我,来吐槽~