github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/bind/table_path_prefix.go (about)

     1  package bind
     2  
     3  import (
     4  	"path"
     5  	"strings"
     6  
     7  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring"
     8  )
     9  
    10  type TablePathPrefix string
    11  
    12  func (tablePathPrefix TablePathPrefix) blockID() blockID {
    13  	return blockPragma
    14  }
    15  
    16  func (tablePathPrefix TablePathPrefix) NormalizePath(folderOrTable string) string {
    17  	switch ch := folderOrTable[0]; ch {
    18  	case '/':
    19  		return folderOrTable
    20  	case '.':
    21  		return path.Join(string(tablePathPrefix), strings.TrimLeft(folderOrTable, "."))
    22  	default:
    23  		return path.Join(string(tablePathPrefix), folderOrTable)
    24  	}
    25  }
    26  
    27  func (tablePathPrefix TablePathPrefix) RewriteQuery(query string, args ...interface{}) (
    28  	yql string, newArgs []interface{}, err error,
    29  ) {
    30  	buffer := xstring.Buffer()
    31  	defer buffer.Free()
    32  
    33  	buffer.WriteString("-- bind TablePathPrefix\n")
    34  	buffer.WriteString("PRAGMA TablePathPrefix(\"")
    35  	buffer.WriteString(string(tablePathPrefix))
    36  	buffer.WriteString("\");\n\n")
    37  	buffer.WriteString(query)
    38  
    39  	return buffer.String(), args, nil
    40  }