This repository has been archived on 2020-04-27. You can view files and clone it, but cannot push or open issues or pull requests.
cmd/xorm/objc.go
Lunny Xiao ac9f151800
All checks were successful
continuous-integration/drone/push Build is passing
move to xorm.io/cmd/xorm
2019-06-17 14:13:41 +08:00

71 lines
1.5 KiB
Go

// Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
//"fmt"
"strings"
"text/template"
"xorm.io/core"
)
var (
ObjcTmpl LangTmpl = LangTmpl{
template.FuncMap{"Mapper": mapper.Table2Obj,
"Type": objcTypeStr,
"UnTitle": unTitle,
},
nil,
genCPlusImports,
}
)
func objcTypeStr(col *core.Column) string {
tp := col.SQLType
name := strings.ToUpper(tp.Name)
switch name {
case core.Bit, core.TinyInt, core.SmallInt, core.MediumInt, core.Int, core.Integer, core.Serial:
return "int"
case core.BigInt, core.BigSerial:
return "long"
case core.Char, core.Varchar, core.TinyText, core.Text, core.MediumText, core.LongText:
return "NSString*"
case core.Date, core.DateTime, core.Time, core.TimeStamp:
return "NSString*"
case core.Decimal, core.Numeric:
return "NSString*"
case core.Real, core.Float:
return "float"
case core.Double:
return "double"
case core.TinyBlob, core.Blob, core.MediumBlob, core.LongBlob, core.Bytea:
return "NSString*"
case core.Bool:
return "BOOL"
default:
return "NSString*"
}
return ""
}
func genObjcImports(tables []*core.Table) map[string]string {
imports := make(map[string]string)
for _, table := range tables {
for _, col := range table.Columns() {
switch objcTypeStr(col) {
case "time_t":
imports[`<time.h>`] = `<time.h>`
case "tstring":
imports["<string>"] = "<string>"
//case "__int64":
// imports[""] = ""
}
}
}
return imports
}