Skip to content

Commit f31ab61

Browse files
authored
Merge pull request #508 from datbeohbbh/datbeohbbh/xorm
Embedding `internal/xsql` package
2 parents 2053cf3 + 74b819b commit f31ab61

File tree

7 files changed

+467
-23
lines changed

7 files changed

+467
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Implemented `driver.RowsColumnTypeDatabaseTypeName` interface in `internal/xsql.rows` struct
2+
* Extended `internal/xsql.conn` struct with methods for getting `YDB` metadata
3+
* Added `scheme.Client` to `internal/xsql.connection` interface
4+
* Added `helpers` package with method for checking existence of table, refactored `sugar.IsTableExists()`
15
* Added checks for nil option to all opts range loops
26
* Moved content of package `internal/ctxlabels` into `internal/xcontext`
37
* Implemented `GRPCStatus` method in `internal/xerrors/transportError`
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package helpers
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"path"
7+
8+
"github.com/ydb-platform/ydb-go-sdk/v3/scheme"
9+
)
10+
11+
func IsTableExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error) {
12+
directory, tableName := path.Split(absTablePath)
13+
d, err := c.ListDirectory(ctx, directory)
14+
if err != nil {
15+
return false, err
16+
}
17+
for _, e := range d.Children {
18+
if e.Name != tableName {
19+
continue
20+
}
21+
if e.Type != scheme.EntryTable {
22+
return false, fmt.Errorf(
23+
"entry '%s' in path '%s' is not a table: %s",
24+
tableName, directory, e.Type.String(),
25+
)
26+
}
27+
return true, nil
28+
}
29+
return false, nil
30+
}

0 commit comments

Comments
 (0)