Dernière activité 1714309050

Révision 7748aa506e67f2b37fbc9d78b3af3d63ab6f2df9

mariadb.sql Brut
1SELECT
2 'type ' || table_name || ' struct {' || CHR(10) || fields || CHR(10) || '}' AS models
3FROM
4 (
5 SELECT
6 table_name,
7 REPLACE(RTRIM(XMLAGG(XMLELEMENT(E, CHR(9) || column_name || CHR(9) || type_info || CHR(9) || annotation || CHR(10))).EXTRACT('//text()').GETCLOBVAL(), CHR(10)), '"', '"') AS fields
8 FROM
9 (
10 SELECT
11 REPLACE(INITCAP(table_name), '_', '') AS table_name,
12 REPLACE(INITCAP(column_name), '_', '') AS column_name,
13 CASE data_type
14 WHEN 'TIMESTAMP' THEN 'time.Time'
15 WHEN 'TIMESTAMP(6)' THEN 'time.Time'
16 WHEN 'TIMESTAMP WITH TIME ZONE' THEN 'time.Time'
17 WHEN 'TIMESTAMP WITH LOCAL TIME ZONE' THEN 'time.Time'
18 WHEN 'LONG' THEN 'int64'
19 WHEN 'NUMBER' THEN
20 CASE
21 WHEN data_precision IS NULL AND data_scale = 0 THEN 'int'
22 WHEN data_precision IS NOT NULL AND data_scale = 0 THEN 'int64'
23 ELSE 'float64'
24 END
25 WHEN 'FLOAT' THEN 'float32'
26 WHEN 'BINARY_FLOAT' THEN 'float32'
27 WHEN 'BINARY_DOUBLE' THEN 'float64'
28 WHEN 'CHAR' THEN 'string'
29 WHEN 'VARCHAR2' THEN 'sql.NullString'
30 WHEN 'NCHAR' THEN 'string'
31 WHEN 'NVARCHAR2' THEN 'string'
32 WHEN 'CLOB' THEN 'go_ora.Clob'
33 WHEN 'NCLOB' THEN 'go_ora.Nlob'
34 WHEN 'BLOB' THEN 'go_ora.Blob'
35 WHEN 'DATE' THEN 'go_ora.NullTimeStamp'
36 WHEN 'RAW' THEN '[]byte'
37 WHEN 'UNDEFINED' THEN 'database.OraUNDEFINED'
38 -- add your own type converters as needed or it will default to 'string'
39 ELSE 'UNKNOWN'
40 END AS type_info,
41 '`json:"' || column_name || '" db:"' || column_name || '"`' AS annotation
42 FROM all_tab_columns
43 WHERE owner = 'DELOPRO'
44 )
45 --WHERE type_info = 'UNKNOWN'
46 GROUP BY table_name
47 )
48--WHERE table_name = 'V8EventVw'
49ORDER BY table_name
oracle.sql Brut
1SELECT
2 'type ' || table_name || ' struct {' || CHR(10) || fields || CHR(10) || '}' AS models
3FROM
4 (
5 SELECT
6 table_name,
7 REPLACE(RTRIM(XMLAGG(XMLELEMENT(E, CHR(9) || column_name || CHR(9) || type_info || CHR(9) || annotation || CHR(10))).EXTRACT('//text()').GETCLOBVAL(), CHR(10)), '"', '"') AS fields
8 FROM
9 (
10 SELECT
11 REPLACE(INITCAP(table_name), '_', '') AS table_name,
12 REPLACE(INITCAP(column_name), '_', '') AS column_name,
13 CASE data_type
14 WHEN 'TIMESTAMP' THEN 'time.Time'
15 WHEN 'TIMESTAMP(6)' THEN 'time.Time'
16 WHEN 'TIMESTAMP WITH TIME ZONE' THEN 'time.Time'
17 WHEN 'TIMESTAMP WITH LOCAL TIME ZONE' THEN 'time.Time'
18 WHEN 'LONG' THEN 'int64'
19 WHEN 'NUMBER' THEN
20 CASE
21 WHEN data_precision IS NULL AND data_scale = 0 THEN 'int'
22 WHEN data_precision IS NOT NULL AND data_scale = 0 THEN 'int64'
23 ELSE 'float64'
24 END
25 WHEN 'FLOAT' THEN 'float32'
26 WHEN 'BINARY_FLOAT' THEN 'float32'
27 WHEN 'BINARY_DOUBLE' THEN 'float64'
28 WHEN 'CHAR' THEN 'string'
29 WHEN 'VARCHAR2' THEN 'sql.NullString'
30 WHEN 'NCHAR' THEN 'string'
31 WHEN 'NVARCHAR2' THEN 'string'
32 WHEN 'CLOB' THEN 'go_ora.Clob'
33 WHEN 'NCLOB' THEN 'go_ora.Nlob'
34 WHEN 'BLOB' THEN 'go_ora.Blob'
35 WHEN 'DATE' THEN 'go_ora.NullTimeStamp'
36 WHEN 'RAW' THEN '[]byte'
37 WHEN 'UNDEFINED' THEN 'database.OraUNDEFINED'
38 -- add your own type converters as needed or it will default to 'string'
39 ELSE 'UNKNOWN'
40 END AS type_info,
41 '`json:"' || column_name || '" db:"' || column_name || '"`' AS annotation
42 FROM all_tab_columns
43 WHERE owner = 'DELOPRO'
44 )
45 --WHERE type_info = 'UNKNOWN'
46 GROUP BY table_name
47 )
48--WHERE table_name = 'V8EventVw'
49ORDER BY table_name
postgres.sql Brut
1WITH models AS (
2 WITH data AS (
3 SELECT
4 replace(initcap(table_name::text), '_', '') table_name,
5 replace(initcap(column_name::text), '_', '') column_name,
6 CASE data_type
7 WHEN 'timestamp without time zone' THEN 'time.Time'
8 WHEN 'timestamp with time zone' THEN 'time.Time'
9 WHEN 'boolean' THEN 'bool'
10 WHEN 'bigint' THEN 'int64'
11 WHEN 'integer' THEN 'int'
12 WHEN 'ARRAY' THEN 'pgtype.Array[string]'
13 WHEN 'date' THEN 'pgtype.Date'
14 WHEN 'character varying' THEN 'string'
15 WHEN 'double precision' THEN 'float64'
16 -- add your own type converters as needed or it will default to 'string'
17 ELSE 'UNKNOWN'
18 END AS type_info,
19 '`json:"' || column_name ||'"`' AS annotation
20 FROM information_schema.columns
21 WHERE table_schema IN ('public')
22 ORDER BY table_schema, table_name, ordinal_position
23 )
24 SELECT table_name, STRING_AGG(E'\t' || column_name || E'\t' || type_info || E'\t' || annotation, E'\n') fields
25 FROM data
26 GROUP BY table_name
27)
28SELECT 'type ' || table_name || E' struct {\n' || fields || E'\n}' models
29FROM models ORDER BY table_name