objc.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2017 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. //"fmt"
  7. "strings"
  8. "text/template"
  9. "github.com/go-xorm/core"
  10. )
  11. var (
  12. ObjcTmpl LangTmpl = LangTmpl{
  13. template.FuncMap{"Mapper": mapper.Table2Obj,
  14. "Type": objcTypeStr,
  15. "UnTitle": unTitle,
  16. },
  17. nil,
  18. genCPlusImports,
  19. }
  20. )
  21. func objcTypeStr(col *core.Column) string {
  22. tp := col.SQLType
  23. name := strings.ToUpper(tp.Name)
  24. switch name {
  25. case core.Bit, core.TinyInt, core.SmallInt, core.MediumInt, core.Int, core.Integer, core.Serial:
  26. return "int"
  27. case core.BigInt, core.BigSerial:
  28. return "long"
  29. case core.Char, core.Varchar, core.TinyText, core.Text, core.MediumText, core.LongText:
  30. return "NSString*"
  31. case core.Date, core.DateTime, core.Time, core.TimeStamp:
  32. return "NSString*"
  33. case core.Decimal, core.Numeric:
  34. return "NSString*"
  35. case core.Real, core.Float:
  36. return "float"
  37. case core.Double:
  38. return "double"
  39. case core.TinyBlob, core.Blob, core.MediumBlob, core.LongBlob, core.Bytea:
  40. return "NSString*"
  41. case core.Bool:
  42. return "BOOL"
  43. default:
  44. return "NSString*"
  45. }
  46. return ""
  47. }
  48. func genObjcImports(tables []*core.Table) map[string]string {
  49. imports := make(map[string]string)
  50. for _, table := range tables {
  51. for _, col := range table.Columns() {
  52. switch objcTypeStr(col) {
  53. case "time_t":
  54. imports[`<time.h>`] = `<time.h>`
  55. case "tstring":
  56. imports["<string>"] = "<string>"
  57. //case "__int64":
  58. // imports[""] = ""
  59. }
  60. }
  61. }
  62. return imports
  63. }