Replace path package with filepath
This commit is contained in:
parent
d6f1f28db8
commit
cab3cc63bf
8 changed files with 35 additions and 43 deletions
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/go-jet/jet/v2/internal/utils/errfmt"
|
||||
"github.com/go-jet/jet/v2/internal/utils/strslice"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/go-jet/jet/v2/generator/metadata"
|
||||
|
|
@ -80,19 +79,12 @@ func init() {
|
|||
flag.StringVar(&tablePkg, "table-pkg", "table", "Relative path for the Table files package from the destination directory.")
|
||||
flag.StringVar(&viewPkg, "view-pkg", "view", "Relative path for the View files package from the destination directory.")
|
||||
flag.StringVar(&enumPkg, "enum-pkg", "enum", "Relative path for the Enum files package from the destination directory.")
|
||||
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
// Convert the OS-specific path separator to slashes for cross-platform compatibility.
|
||||
destDir = filepath.ToSlash(destDir)
|
||||
modelPkg = filepath.ToSlash(modelPkg)
|
||||
tablePkg = filepath.ToSlash(tablePkg)
|
||||
viewPkg = filepath.ToSlash(viewPkg)
|
||||
enumPkg = filepath.ToSlash(enumPkg)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
if dsn == "" && (source == "" || host == "" || port == 0 || user == "" || dbName == "") {
|
||||
printErrorAndExit("ERROR: required flag(s) missing")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-jet/jet/v2/generator/metadata"
|
||||
|
|
@ -66,7 +66,7 @@ func GenerateDSN(dsn, schema, destDir string, templates ...template.Template) er
|
|||
return fmt.Errorf("failed to get '%s' schema metadata: %w", schema, err)
|
||||
}
|
||||
|
||||
dirPath := path.Join(destDir, cfg.Database)
|
||||
dirPath := filepath.Join(destDir, cfg.Database)
|
||||
|
||||
err = template.ProcessSchema(dirPath, schemaMetadata, generatorTemplate)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/go-jet/jet/v2/internal/utils/dbidentifier"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgtype"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -23,7 +23,7 @@ type Model struct {
|
|||
|
||||
// PackageName returns package name of model types
|
||||
func (m Model) PackageName() string {
|
||||
return path.Base(m.Path)
|
||||
return filepath.Base(m.Path)
|
||||
}
|
||||
|
||||
// UsePath returns new Model template with replaced file path
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/v2/internal/utils/filesys"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ func ProcessSchema(dirPath string, schemaMetaData metadata.Schema, generatorTemp
|
|||
}
|
||||
|
||||
schemaTemplate := generatorTemplate.Schema(schemaMetaData)
|
||||
schemaPath := path.Join(dirPath, schemaTemplate.Path)
|
||||
schemaPath := filepath.Join(dirPath, schemaTemplate.Path)
|
||||
|
||||
fmt.Println("Destination directory:", schemaPath)
|
||||
fmt.Println("Cleaning up destination directory...")
|
||||
|
|
@ -50,7 +50,7 @@ func processModel(dirPath string, schemaMetaData metadata.Schema, schemaTemplate
|
|||
return nil
|
||||
}
|
||||
|
||||
modelDirPath := path.Join(dirPath, modelTemplate.Path)
|
||||
modelDirPath := filepath.Join(dirPath, modelTemplate.Path)
|
||||
|
||||
err := filesys.EnsureDirPathExist(modelDirPath)
|
||||
if err != nil {
|
||||
|
|
@ -83,7 +83,7 @@ func processSQLBuilder(dirPath string, dialect jet.Dialect, schemaMetaData metad
|
|||
return nil
|
||||
}
|
||||
|
||||
sqlBuilderPath := path.Join(dirPath, sqlBuilderTemplate.Path)
|
||||
sqlBuilderPath := filepath.Join(dirPath, sqlBuilderTemplate.Path)
|
||||
|
||||
err := processTableSQLBuilder("table", sqlBuilderPath, dialect, schemaMetaData, schemaMetaData.TablesMetaData, sqlBuilderTemplate)
|
||||
if err != nil {
|
||||
|
|
@ -117,7 +117,7 @@ func processEnumSQLBuilder(dirPath string, dialect jet.Dialect, enumsMetaData []
|
|||
continue
|
||||
}
|
||||
|
||||
enumSQLBuilderPath := path.Join(dirPath, enumTemplate.Path)
|
||||
enumSQLBuilderPath := filepath.Join(dirPath, enumTemplate.Path)
|
||||
|
||||
err := filesys.EnsureDirPathExist(enumSQLBuilderPath)
|
||||
if err != nil {
|
||||
|
|
@ -182,7 +182,7 @@ func processTableSQLBuilder(fileTypes, dirPath string,
|
|||
continue
|
||||
}
|
||||
|
||||
tableSQLBuilderPath := path.Join(dirPath, tableSQLBuilder.Path)
|
||||
tableSQLBuilderPath := filepath.Join(dirPath, tableSQLBuilder.Path)
|
||||
|
||||
err := filesys.EnsureDirPathExist(tableSQLBuilderPath)
|
||||
if err != nil {
|
||||
|
|
@ -255,7 +255,7 @@ func generateUseSchemaFunc(dirPath, fileTypes string, builders []TableSQLBuilder
|
|||
return fmt.Errorf("failed to generate use schema template: %w", err)
|
||||
}
|
||||
|
||||
basePath := path.Join(dirPath, builders[0].Path)
|
||||
basePath := filepath.Join(dirPath, builders[0].Path)
|
||||
fileName := fileTypes + "_use_schema"
|
||||
|
||||
err = filesys.FormatAndSaveGoFile(basePath, fileName, text)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/go-jet/jet/v2/generator/metadata"
|
||||
"github.com/go-jet/jet/v2/internal/utils/dbidentifier"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
|
@ -90,7 +90,7 @@ func DefaultViewSQLBuilder(viewMetaData metadata.Table) ViewSQLBuilder {
|
|||
|
||||
// PackageName returns package name of table sql builder types
|
||||
func (tb TableSQLBuilder) PackageName() string {
|
||||
return path.Base(tb.Path)
|
||||
return filepath.Base(tb.Path)
|
||||
}
|
||||
|
||||
// UsePath returns new TableSQLBuilder with new relative path set
|
||||
|
|
@ -228,7 +228,7 @@ func DefaultEnumSQLBuilder(enumMetaData metadata.Enum) EnumSQLBuilder {
|
|||
|
||||
// PackageName returns enum sql builder package name
|
||||
func (e EnumSQLBuilder) PackageName() string {
|
||||
return path.Base(e.Path)
|
||||
return filepath.Base(e.Path)
|
||||
}
|
||||
|
||||
// UsePath returns new EnumSQLBuilder with new path set
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ package file
|
|||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Exists expects file to exist on path constructed from pathElems and returns content of the file
|
||||
func Exists(t *testing.T, pathElems ...string) (fileContent string) {
|
||||
modelFilePath := path.Join(pathElems...)
|
||||
modelFilePath := filepath.Join(pathElems...)
|
||||
file, err := os.ReadFile(modelFilePath) // #nosec G304
|
||||
require.Nil(t, err)
|
||||
require.NotEmpty(t, file)
|
||||
|
|
@ -18,7 +18,7 @@ func Exists(t *testing.T, pathElems ...string) (fileContent string) {
|
|||
|
||||
// NotExists expects file not to exist on path constructed from pathElems
|
||||
func NotExists(t *testing.T, pathElems ...string) {
|
||||
modelFilePath := path.Join(pathElems...)
|
||||
modelFilePath := filepath.Join(pathElems...)
|
||||
_, err := os.ReadFile(modelFilePath) // #nosec G304
|
||||
require.True(t, os.IsNotExist(err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,18 @@ import (
|
|||
"github.com/go-jet/jet/v2/tests/dbconfig"
|
||||
file2 "github.com/go-jet/jet/v2/tests/internal/utils/file"
|
||||
"github.com/stretchr/testify/require"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const tempTestDir = "./.tempTestDir"
|
||||
|
||||
var defaultModelPath = path.Join(tempTestDir, "dvds/model")
|
||||
var defaultActorModelFilePath = path.Join(tempTestDir, "dvds/model", "actor.go")
|
||||
var defaultTableSQLBuilderFilePath = path.Join(tempTestDir, "dvds/table")
|
||||
var defaultViewSQLBuilderFilePath = path.Join(tempTestDir, "dvds/view")
|
||||
var defaultEnumSQLBuilderFilePath = path.Join(tempTestDir, "dvds/enum")
|
||||
var defaultActorSQLBuilderFilePath = path.Join(tempTestDir, "dvds/table", "actor.go")
|
||||
var defaultModelPath = filepath.Join(tempTestDir, "dvds/model")
|
||||
var defaultActorModelFilePath = filepath.Join(tempTestDir, "dvds/model", "actor.go")
|
||||
var defaultTableSQLBuilderFilePath = filepath.Join(tempTestDir, "dvds/table")
|
||||
var defaultViewSQLBuilderFilePath = filepath.Join(tempTestDir, "dvds/view")
|
||||
var defaultEnumSQLBuilderFilePath = filepath.Join(tempTestDir, "dvds/enum")
|
||||
var defaultActorSQLBuilderFilePath = filepath.Join(tempTestDir, "dvds/table", "actor.go")
|
||||
|
||||
func dbConnection(dbName string) mysql2.DBConnection {
|
||||
if sourceIsMariaDB() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package postgres
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/go-jet/jet/v2/generator/metadata"
|
||||
|
|
@ -20,13 +20,13 @@ import (
|
|||
|
||||
const tempTestDir = "./.tempTestDir"
|
||||
|
||||
var defaultModelPath = path.Join(tempTestDir, "jetdb/dvds/model")
|
||||
var defaultSqlBuilderPath = path.Join(tempTestDir, "jetdb/dvds/table")
|
||||
var defaultActorModelFilePath = path.Join(tempTestDir, "jetdb/dvds/model", "actor.go")
|
||||
var defaultTableSQLBuilderFilePath = path.Join(tempTestDir, "jetdb/dvds/table")
|
||||
var defaultViewSQLBuilderFilePath = path.Join(tempTestDir, "jetdb/dvds/view")
|
||||
var defaultEnumSQLBuilderFilePath = path.Join(tempTestDir, "jetdb/dvds/enum")
|
||||
var defaultActorSQLBuilderFilePath = path.Join(tempTestDir, "jetdb/dvds/table", "actor.go")
|
||||
var defaultModelPath = filepath.Join(tempTestDir, "jetdb/dvds/model")
|
||||
var defaultSqlBuilderPath = filepath.Join(tempTestDir, "jetdb/dvds/table")
|
||||
var defaultActorModelFilePath = filepath.Join(tempTestDir, "jetdb/dvds/model", "actor.go")
|
||||
var defaultTableSQLBuilderFilePath = filepath.Join(tempTestDir, "jetdb/dvds/table")
|
||||
var defaultViewSQLBuilderFilePath = filepath.Join(tempTestDir, "jetdb/dvds/view")
|
||||
var defaultEnumSQLBuilderFilePath = filepath.Join(tempTestDir, "jetdb/dvds/enum")
|
||||
var defaultActorSQLBuilderFilePath = filepath.Join(tempTestDir, "jetdb/dvds/table", "actor.go")
|
||||
|
||||
var dbConnection = postgres.DBConnection{
|
||||
Host: dbconfig.PgHost,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue