fix: readers and linting issues
This commit is contained in:
@@ -67,15 +67,6 @@ func (r *Reader) ReadTable() (*models.Table, error) {
|
||||
return schema.Tables[0], nil
|
||||
}
|
||||
|
||||
// stripQuotes removes surrounding quotes from an identifier
|
||||
func stripQuotes(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
if len(s) >= 2 && ((s[0] == '"' && s[len(s)-1] == '"') || (s[0] == '\'' && s[len(s)-1] == '\'')) {
|
||||
return s[1 : len(s)-1]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// parsePrisma parses Prisma schema content and returns a Database model
|
||||
func (r *Reader) parsePrisma(content string) (*models.Database, error) {
|
||||
db := models.InitDatabase("database")
|
||||
@@ -239,8 +230,8 @@ func (r *Reader) parseModelFields(lines []string, table *models.Table) {
|
||||
if matches := fieldRegex.FindStringSubmatch(trimmed); matches != nil {
|
||||
fieldName := matches[1]
|
||||
fieldType := matches[2]
|
||||
modifier := matches[3] // ? or []
|
||||
attributes := matches[4] // @... part
|
||||
modifier := matches[3] // ? or []
|
||||
attributes := matches[4] // @... part
|
||||
|
||||
column := r.parseField(fieldName, fieldType, modifier, attributes, table)
|
||||
if column != nil {
|
||||
@@ -370,9 +361,10 @@ func (r *Reader) extractDefaultValue(attributes string) string {
|
||||
i := start
|
||||
|
||||
for i < len(attributes) && depth > 0 {
|
||||
if attributes[i] == '(' {
|
||||
switch attributes[i] {
|
||||
case '(':
|
||||
depth++
|
||||
} else if attributes[i] == ')' {
|
||||
case ')':
|
||||
depth--
|
||||
}
|
||||
i++
|
||||
@@ -479,11 +471,11 @@ func (r *Reader) parseBlockAttribute(attrName, content string, table *models.Tab
|
||||
|
||||
// relationField stores information about a relation field for second-pass processing
|
||||
type relationField struct {
|
||||
tableName string
|
||||
fieldName string
|
||||
relatedModel string
|
||||
isArray bool
|
||||
relationAttr string
|
||||
tableName string
|
||||
fieldName string
|
||||
relatedModel string
|
||||
isArray bool
|
||||
relationAttr string
|
||||
}
|
||||
|
||||
// resolveRelationships performs a second pass to resolve @relation attributes
|
||||
|
||||
Reference in New Issue
Block a user