seaweedfs/weed/filer/ydb/ydb_types.go

57 lines
1.8 KiB
Go
Raw Normal View History

//go:build ydb
// +build ydb
package ydb
2022-05-01 21:07:47 +00:00
import (
2022-05-03 15:16:00 +00:00
"fmt"
2022-05-01 21:07:47 +00:00
"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"
)
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"`
}
type FileMetas []FileMeta
2022-05-01 21:07:47 +00:00
2022-05-03 12:52:23 +00:00
func (fm *FileMeta) queryParameters(ttlSec int32) *table.QueryParameters {
var expireAtValue types.Value
if ttlSec > 0 {
expireAtValue = types.Uint32Value(uint32(ttlSec))
} else {
expireAtValue = types.NullValue(types.TypeUint32)
}
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-03 12:52:23 +00:00
table.ValueParam("$meta", types.StringValue(fm.Meta)),
table.ValueParam("$expire_at", expireAtValue))
2022-05-01 21:07:47 +00:00
}
2022-05-02 07:42:20 +00:00
func createTableOptions() []options.CreateTableOption {
2022-05-03 12:52:23 +00:00
columnUnit := options.TimeToLiveUnitSeconds
2022-05-02 07:42:20 +00:00
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-03 12:52:23 +00:00
options.WithColumn("expire_at", types.Optional(types.TypeUint32)),
2022-05-02 07:42:20 +00:00
options.WithPrimaryKeyColumn("dir_hash", "name"),
2022-05-03 12:52:23 +00:00
options.WithTimeToLiveSettings(options.TimeToLiveSettings{
ColumnName: "expire_at",
ColumnUnit: &columnUnit,
Mode: options.TimeToLiveModeValueSinceUnixEpoch},
),
2022-05-02 07:42:20 +00:00
}
}
2022-05-03 15:16:00 +00:00
func withPragma(prefix *string, query string) *string {
queryWithPragma := fmt.Sprintf(query, *prefix)
return &queryWithPragma
2022-05-02 07:42:20 +00:00
}