@@ -27,83 +27,79 @@ type PrimaryKeyColumn struct {
27
27
func GetPrimaryKeyColumns (ctx context.Context ) (cols []PrimaryKeyColumn , err error ) {
28
28
defer errs .WrapWithFuncParams (& err , ctx )
29
29
30
- err = db .QueryRows (ctx , `
31
- select
32
- tc.table_schema||'.'||tc.table_name as "table",
33
- kc.column_name as "column",
34
- col.data_type as "type",
35
- (select exists(
36
- select from information_schema.table_constraints as fk_tc
37
- inner join information_schema.key_column_usage as fk_kc
38
- on fk_kc.table_schema = fk_tc.table_schema
39
- and fk_kc.table_name = fk_tc.table_name
40
- and fk_kc.constraint_name = fk_tc.constraint_name
41
- where fk_tc.constraint_type = 'FOREIGN KEY'
42
- and fk_tc.table_schema = tc.table_schema
43
- and fk_tc.table_name = tc.table_name
44
- and fk_kc.column_name = kc.column_name
45
- )) as "foreign_key"
46
- from information_schema.table_constraints as tc
47
- inner join information_schema.key_column_usage as kc
48
- on kc.table_schema = tc.table_schema
49
- and kc.table_name = tc.table_name
50
- and kc.constraint_name = tc.constraint_name
51
- inner join information_schema.columns as col
52
- on col.table_schema = tc.table_schema
53
- and col.table_name = tc.table_name
54
- and col.column_name = kc.column_name
55
- where tc.constraint_type = 'PRIMARY KEY'
56
- and kc.ordinal_position is not null
57
- order by
58
- tc.table_schema,
59
- tc.table_name` ,
60
- ).ScanStructSlice (& cols )
61
- if err != nil {
62
- return nil , err
63
- }
64
- return cols , nil
30
+ return db .QueryStructSlice [PrimaryKeyColumn ](ctx ,
31
+ /*sql*/ `
32
+ select
33
+ tc.table_schema||'.'||tc.table_name as "table",
34
+ kc.column_name as "column",
35
+ col.data_type as "type",
36
+ (select exists(
37
+ select from information_schema.table_constraints as fk_tc
38
+ inner join information_schema.key_column_usage as fk_kc
39
+ on fk_kc.table_schema = fk_tc.table_schema
40
+ and fk_kc.table_name = fk_tc.table_name
41
+ and fk_kc.constraint_name = fk_tc.constraint_name
42
+ where fk_tc.constraint_type = 'FOREIGN KEY'
43
+ and fk_tc.table_schema = tc.table_schema
44
+ and fk_tc.table_name = tc.table_name
45
+ and fk_kc.column_name = kc.column_name
46
+ )) as "foreign_key"
47
+ from information_schema.table_constraints as tc
48
+ inner join information_schema.key_column_usage as kc
49
+ on kc.table_schema = tc.table_schema
50
+ and kc.table_name = tc.table_name
51
+ and kc.constraint_name = tc.constraint_name
52
+ inner join information_schema.columns as col
53
+ on col.table_schema = tc.table_schema
54
+ and col.table_name = tc.table_name
55
+ and col.column_name = kc.column_name
56
+ where tc.constraint_type = 'PRIMARY KEY'
57
+ and kc.ordinal_position is not null
58
+ order by
59
+ tc.table_schema,
60
+ tc.table_name
61
+ ` ,
62
+ )
65
63
}
66
64
67
65
func GetPrimaryKeyColumnsOfType (ctx context.Context , pkType string ) (cols []PrimaryKeyColumn , err error ) {
68
66
defer errs .WrapWithFuncParams (& err , ctx , pkType )
69
67
70
- err = db .QueryRows (ctx , `
71
- select
72
- tc.table_schema||'.'||tc.table_name as "table",
73
- kc.column_name as "column",
74
- col.data_type as "type",
75
- (select exists(
76
- select from information_schema.table_constraints as fk_tc
77
- inner join information_schema.key_column_usage as fk_kc
78
- on fk_kc.table_schema = fk_tc.table_schema
79
- and fk_kc.table_name = fk_tc.table_name
80
- and fk_kc.constraint_name = fk_tc.constraint_name
81
- where fk_tc.constraint_type = 'FOREIGN KEY'
82
- and fk_tc.table_schema = tc.table_schema
83
- and fk_tc.table_name = tc.table_name
84
- and fk_kc.column_name = kc.column_name
85
- )) as "foreign_key"
86
- from information_schema.table_constraints as tc
87
- inner join information_schema.key_column_usage as kc
88
- on kc.table_schema = tc.table_schema
89
- and kc.table_name = tc.table_name
90
- and kc.constraint_name = tc.constraint_name
91
- inner join information_schema.columns as col
92
- on col.table_schema = tc.table_schema
93
- and col.table_name = tc.table_name
94
- and col.column_name = kc.column_name
95
- where tc.constraint_type = 'PRIMARY KEY'
96
- and kc.ordinal_position is not null
97
- and col.data_type = $1
98
- order by
99
- tc.table_schema,
100
- tc.table_name` ,
101
- pkType ,
102
- ).ScanStructSlice (& cols )
103
- if err != nil {
104
- return nil , err
105
- }
106
- return cols , nil
68
+ return db .QueryStructSlice [PrimaryKeyColumn ](ctx ,
69
+ /*sql*/ `
70
+ select
71
+ tc.table_schema||'.'||tc.table_name as "table",
72
+ kc.column_name as "column",
73
+ col.data_type as "type",
74
+ (select exists(
75
+ select from information_schema.table_constraints as fk_tc
76
+ inner join information_schema.key_column_usage as fk_kc
77
+ on fk_kc.table_schema = fk_tc.table_schema
78
+ and fk_kc.table_name = fk_tc.table_name
79
+ and fk_kc.constraint_name = fk_tc.constraint_name
80
+ where fk_tc.constraint_type = 'FOREIGN KEY'
81
+ and fk_tc.table_schema = tc.table_schema
82
+ and fk_tc.table_name = tc.table_name
83
+ and fk_kc.column_name = kc.column_name
84
+ )) as "foreign_key"
85
+ from information_schema.table_constraints as tc
86
+ inner join information_schema.key_column_usage as kc
87
+ on kc.table_schema = tc.table_schema
88
+ and kc.table_name = tc.table_name
89
+ and kc.constraint_name = tc.constraint_name
90
+ inner join information_schema.columns as col
91
+ on col.table_schema = tc.table_schema
92
+ and col.table_name = tc.table_name
93
+ and col.column_name = kc.column_name
94
+ where tc.constraint_type = 'PRIMARY KEY'
95
+ and kc.ordinal_position is not null
96
+ and col.data_type = $1
97
+ order by
98
+ tc.table_schema,
99
+ tc.table_name
100
+ ` ,
101
+ pkType , // $1
102
+ )
107
103
}
108
104
109
105
type TableRowWithPrimaryKey struct {
@@ -154,7 +150,7 @@ var RenderUUIDPrimaryKeyRefsHTML = http.HandlerFunc(func(writer http.ResponseWri
154
150
pk , err := uu .IDFromString (request .URL .Query ().Get ("pk" ))
155
151
if err != nil {
156
152
title = "Primary Key UUID"
157
- mainContent = `
153
+ mainContent = /*html*/ `
158
154
<form onsubmit="event.preventDefault();location='.?pk='+encodeURIComponent(document.getElementById('uuid').value.trim())">
159
155
<input type="text" size="40" id="uuid"/>
160
156
<input type="submit" value="Look up"/>
@@ -222,7 +218,7 @@ var RenderUUIDPrimaryKeyRefsHTML = http.HandlerFunc(func(writer http.ResponseWri
222
218
writer .Write (buf .Bytes ()) //#nosec G104
223
219
})
224
220
225
- var htmlTemplate = `<!DOCTYPE html>
221
+ var htmlTemplate = /*html*/ `<!DOCTYPE html>
226
222
<html lang="en">
227
223
<head>
228
224
<meta charset="utf-8">
@@ -254,9 +250,9 @@ var htmlTemplate = `<!DOCTYPE html>
254
250
</body>
255
251
</html>`
256
252
257
- const StyleAllMonospace = `<style>* { font-family: "Lucida Console", Monaco, monospace; }</style>`
253
+ const StyleAllMonospace = /*html*/ `<style>* { font-family: "Lucida Console", Monaco, monospace; }</style>`
258
254
259
- const StyleDefaultTable = `<style>
255
+ const StyleDefaultTable = /*html*/ `<style>
260
256
table {
261
257
margin-top: 1em;
262
258
margin-bottom: 1em;
0 commit comments