当前位置: 首页 > 工具软件 > STSdb > 使用案例 >

STSdb4

慎俊雄
2023-12-01
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; }
}





转载于:https://www.cnblogs.com/cxwcdxw/p/4691084.html

 类似资料:

相关阅读

相关文章

相关问答