seaweedfs/weed/filer/ydb/ydb_types.go

42 lines
1.3 KiB
Go
Raw Normal View History

package ydb
2022-05-01 21:07:47 +00:00
import (
"github.com/ydb-platform/ydb-go-sdk/v3/table"
2022-05-02 07:42:20 +00:00
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
2022-05-01 21:07:47 +00:00
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)
//go:generate ydbgen
//ydb:gen
type FileMeta struct {
DirHash int64 `ydb:"type:int64"`
Name string `ydb:"type:utf8"`
Directory string `ydb:"type:utf8"`
2022-05-02 19:11:37 +00:00
Meta []byte `ydb:"type:string"`
}
//ydb:gen scan,value
type FileMetas []FileMeta
2022-05-01 21:07:47 +00:00
2022-05-02 07:42:20 +00:00
func (fm *FileMeta) queryParameters() *table.QueryParameters {
2022-05-01 21:07:47 +00:00
return table.NewQueryParameters(
table.ValueParam("$dir_hash", types.Int64Value(fm.DirHash)),
table.ValueParam("$directory", types.UTF8Value(fm.Directory)),
2022-05-03 10:18:28 +00:00
table.ValueParam("$name", types.UTF8Value(fm.Name)),
2022-05-01 21:07:47 +00:00
table.ValueParam("$meta", types.StringValue(fm.Meta)))
}
2022-05-02 07:42:20 +00:00
func createTableOptions() []options.CreateTableOption {
return []options.CreateTableOption{
2022-05-02 19:11:37 +00:00
options.WithColumn("dir_hash", types.Optional(types.TypeInt64)),
2022-05-02 17:23:07 +00:00
options.WithColumn("directory", types.Optional(types.TypeUTF8)),
2022-05-03 10:18:28 +00:00
options.WithColumn("name", types.Optional(types.TypeUTF8)),
2022-05-02 17:23:07 +00:00
options.WithColumn("meta", types.Optional(types.TypeString)),
2022-05-02 07:42:20 +00:00
options.WithPrimaryKeyColumn("dir_hash", "name"),
}
}
2022-05-02 10:33:29 +00:00
func withPragma(prefix string, query string) string {
2022-05-02 07:42:20 +00:00
return `PRAGMA TablePathPrefix("` + prefix + `");` + query
}