功能:增强 Schema 系统和添加新示例

- 扩展 Schema 支持更多数据类型(Duration、URL、JSON 等)
- 优化 SSTable 编码解码性能
- 添加多个新示例程序:
  - all_types: 展示所有支持的数据类型
  - new_types: 演示新增类型的使用
  - struct_tags: 展示结构体标签功能
  - time_duration: 时间和持续时间处理示例
- 完善测试用例和文档
- 优化代码结构和错误处理
This commit is contained in:
2025-10-10 00:20:45 +08:00
parent 6d04487789
commit 77087d36c6
41 changed files with 3008 additions and 452 deletions

View File

@@ -12,7 +12,7 @@ func TestIndexVersionControl(t *testing.T) {
defer os.RemoveAll(dir)
testSchema, err := NewSchema("test", []Field{
{Name: "name", Type: FieldTypeString, Indexed: true, Comment: "名称"},
{Name: "name", Type: String, Indexed: true, Comment: "名称"},
})
if err != nil {
t.Fatal(err)
@@ -76,7 +76,7 @@ func TestIncrementalUpdate(t *testing.T) {
defer os.RemoveAll(dir)
testSchema, err := NewSchema("test", []Field{
{Name: "name", Type: FieldTypeString, Indexed: true, Comment: "名称"},
{Name: "name", Type: String, Indexed: true, Comment: "名称"},
})
if err != nil {
t.Fatal(err)
@@ -150,7 +150,7 @@ func TestNeedsUpdate(t *testing.T) {
defer os.RemoveAll(dir)
testSchema, err := NewSchema("test", []Field{
{Name: "name", Type: FieldTypeString, Indexed: true, Comment: "名称"},
{Name: "name", Type: String, Indexed: true, Comment: "名称"},
})
if err != nil {
t.Fatal(err)
@@ -184,8 +184,8 @@ func TestIndexPersistence(t *testing.T) {
// 创建 Schema
testSchema, err := NewSchema("test", []Field{
{Name: "name", Type: FieldTypeString, Indexed: true, Comment: "名称"},
{Name: "age", Type: FieldTypeInt64, Indexed: true, Comment: "年龄"},
{Name: "name", Type: String, Indexed: true, Comment: "名称"},
{Name: "age", Type: Int64, Indexed: true, Comment: "年龄"},
})
if err != nil {
t.Fatal(err)
@@ -266,7 +266,7 @@ func TestIndexDropWithFile(t *testing.T) {
defer os.RemoveAll(dir)
testSchema, err := NewSchema("test", []Field{
{Name: "name", Type: FieldTypeString, Indexed: true, Comment: "名称"},
{Name: "name", Type: String, Indexed: true, Comment: "名称"},
})
if err != nil {
t.Fatal(err)
@@ -306,9 +306,9 @@ func TestIndexQueryIntegration(t *testing.T) {
// 1. 创建带索引字段的 Schema
schema, err := NewSchema("users", []Field{
{Name: "name", Type: FieldTypeString, Indexed: false},
{Name: "email", Type: FieldTypeString, Indexed: true}, // email 字段有索引
{Name: "age", Type: FieldTypeInt64, Indexed: false},
{Name: "name", Type: String, Indexed: false},
{Name: "email", Type: String, Indexed: true}, // email 字段有索引
{Name: "age", Type: Int64, Indexed: false},
})
if err != nil {
t.Fatal(err)
@@ -469,9 +469,9 @@ func TestIndexPersistenceAcrossRestart(t *testing.T) {
// 1. 第一次打开:创建数据和索引
{
schema, err := NewSchema("products", []Field{
{Name: "name", Type: FieldTypeString, Indexed: false},
{Name: "category", Type: FieldTypeString, Indexed: true},
{Name: "price", Type: FieldTypeInt64, Indexed: false},
{Name: "name", Type: String, Indexed: false},
{Name: "category", Type: String, Indexed: true},
{Name: "price", Type: Int64, Indexed: false},
})
if err != nil {
t.Fatal(err)