test_sql.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package test
  2. import (
  3. uuid "github.com/satori/go.uuid"
  4. "strings"
  5. )
  6. const (
  7. parseSqlInsert = `insert into students (id, name, age, rate, time, is_right) values ('aaa', 'yjp', 5, 92.5, parse_time('2024-01-01 00:00:00', '2006-01-02 15:04:05'), false)`
  8. parseSqlDelete = `delete from students where id = 'aaa' AND name = 'yjp' AND age < 100 AND describe IN ('yjp')`
  9. parseSqlUpdate = `update students set name = 'yjp', age = 5, age = 5, rate = 92.5, time = parse_time('2024-01-01 00:00:00', '2006-01-02 15:04:05'), is_right = false where id = 'aaa' AND name = 'yjp' AND age < 100 AND describe IN ('yjp')`
  10. parseSqlSelectWithJoin = `select id, name, age from students
  11. left join classes on students.id = classes.student_id
  12. left join identities on students.id = identities.student_id
  13. where students.id = 'aaa'
  14. order by students.name desc
  15. limit 20 offset 2`
  16. parseSqlSelectWithSubQuery = `select * from (select * from class where id = 'bbb') where students.id = 'aaa' and students.age = 3`
  17. parseSqlSelectWithGroupBy = `select count(*) from students group by name, age having name = 'aaa' and age = 5`
  18. )
  19. const (
  20. sqlInsertFormat = `insert into %s (id, name, time, table_num) values ('%s', '%s', parse_time('%s', '2006-01-02 15:04:05'), %d)`
  21. sqlDeleteFormat = `delete from %s where id = '%s'`
  22. sqlUpdateFormat = `update %s set name = '%s', time = parse_time('%s', '2006-01-02 15:04:05'), table_num = %d where id = '%s'`
  23. sqlSelectFormat = `select * from %s where id = '%s'`
  24. sqlCountFormat = `select count(*) as count from %s where id = '%s'`
  25. )
  26. const (
  27. dpsAddress = "localhost:30170"
  28. testDatabaseID = "ee2d7dabe56646ce835d80873348ee0e"
  29. )
  30. var tableModelDescribe = map[string]string{
  31. "ID": "gorm:\"primary_key;type:varchar(32);comment:id;\"",
  32. "Name": "gorm:\"not null;type:varchar(128);comment:数据库名称;\"",
  33. "Time": "gorm:\"not null;type:timestamp with time zone;comment:数据库时间;\"",
  34. "TableNum": "gorm:\"not null;type:integer;comment:数据库表数量;\"",
  35. }
  36. func getUUID() string {
  37. return uuid.NewV4().String()
  38. }
  39. func simpleUUID() string {
  40. return strings.ReplaceAll(getUUID(), "-", "")
  41. }