A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

95 righe
1.7 KiB

  1. /*
  2. * Copyright © 2019 Musing Studio LLC.
  3. *
  4. * This file is part of WriteFreely.
  5. *
  6. * WriteFreely is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License, included
  8. * in the LICENSE file in this source code package.
  9. */
  10. package migrations
  11. import (
  12. "fmt"
  13. )
  14. // TODO: use now() from writefreely pkg
  15. func (db *datastore) now() string {
  16. if db.driverName == driverSQLite {
  17. return "strftime('%Y-%m-%d %H:%M:%S','now')"
  18. }
  19. return "NOW()"
  20. }
  21. func (db *datastore) typeInt() string {
  22. if db.driverName == driverSQLite {
  23. return "INTEGER"
  24. }
  25. return "INT"
  26. }
  27. func (db *datastore) typeSmallInt() string {
  28. if db.driverName == driverSQLite {
  29. return "INTEGER"
  30. }
  31. return "SMALLINT"
  32. }
  33. func (db *datastore) typeTinyInt() string {
  34. if db.driverName == driverSQLite {
  35. return "INTEGER"
  36. }
  37. return "TINYINT"
  38. }
  39. func (db *datastore) typeText() string {
  40. return "TEXT"
  41. }
  42. func (db *datastore) typeChar(l int) string {
  43. if db.driverName == driverSQLite {
  44. return "TEXT"
  45. }
  46. return fmt.Sprintf("CHAR(%d)", l)
  47. }
  48. func (db *datastore) typeVarChar(l int) string {
  49. if db.driverName == driverSQLite {
  50. return "TEXT"
  51. }
  52. return fmt.Sprintf("VARCHAR(%d)", l)
  53. }
  54. func (db *datastore) typeBool() string {
  55. if db.driverName == driverSQLite {
  56. return "INTEGER"
  57. }
  58. return "TINYINT(1)"
  59. }
  60. func (db *datastore) typeDateTime() string {
  61. return "DATETIME"
  62. }
  63. func (db *datastore) collateMultiByte() string {
  64. if db.driverName == driverSQLite {
  65. return ""
  66. }
  67. return " COLLATE utf8_bin"
  68. }
  69. func (db *datastore) engine() string {
  70. if db.driverName == driverSQLite {
  71. return ""
  72. }
  73. return " ENGINE = InnoDB"
  74. }
  75. func (db *datastore) after(colName string) string {
  76. if db.driverName == driverSQLite {
  77. return ""
  78. }
  79. return " AFTER " + colName
  80. }