11package sqlbless
22
33import (
4+ _ "embed"
45 "strings"
56 "time"
67
@@ -13,6 +14,12 @@ const (
1314 mySQLDateTimeTzLayout = "2006-01-02 15:04:05.999999999-07:00"
1415)
1516
17+ //go:embed tables.sql
18+ var tablesSql string
19+
20+ //go:embed columns.sql
21+ var columnsSql string
22+
1623var mySQLTypeNameToFormat = map [string ]string {
1724 "DATETIME" : dialect .DateTimeLayout ,
1825 "TIMESTAMP" : dialect .DateTimeLayout ,
@@ -56,37 +63,9 @@ func formatValue(typeName string, value any) (string, bool) {
5663}
5764
5865var mySqlSpec = & dialect.Entry {
59- Usage : `sqlbless mysql <USERNAME>:<PASSWORD>@/<DBNAME>` ,
60- SQLForColumns : `
61- select ordinal_position as "ID",
62- column_name as "NAME",
63- case
64- when character_maximum_length is not null then
65- concat(data_type,'(',character_maximum_length,')')
66- when datetime_precision is not null then
67- concat(data_type,'(',datetime_precision,')')
68- else data_type
69- end as "TYPE",
70- case is_nullable
71- when "YES" then 'NULL'
72- else 'NOT NULL'
73- end as "NULL?"
74- from information_schema.columns
75- join (select ? as x) v
76- where table_name = REGEXP_REPLACE(v.x,'^[^\\.]*\\.','')
77- and table_schema =
78- case
79- when instr(v.x,'.') >= 1 then
80- regexp_replace(v.x,'\\.[^\\.]*$','')
81- else database()
82- end
83- order by ordinal_position` ,
84- SQLForTables : `
85- select concat(table_schema,'.',table_name) as FULL_NAME,
86- tables.* from information_schema.tables
87- where table_type = 'BASE TABLE'
88- and table_schema
89- not in ('mysql', 'information_schema', 'performance_schema', 'sys')` ,
66+ Usage : `sqlbless mysql <USERNAME>:<PASSWORD>@/<DBNAME>` ,
67+ SQLForColumns : columnsSql ,
68+ SQLForTables : tablesSql ,
9069 TypeConverterFor : typeNameToConv ,
9170 PlaceHolder : & dialect.PlaceHolderQuestion {},
9271 TableNameField : "FULL_NAME" ,
0 commit comments