Repository navigation
Expand file tree
/
Copy pathfilter.go
More file actions
133 lines (129 loc) · 5.36 KB
/
Copy pathfilter.go
File metadata and controls
133 lines (129 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package dbmeta
// Args builds the argument map for a query from the usual filter axes. It is a
// convenience: a caller can pass a plain map instead.
//
// Only the fields that are set are included, so a query that does not take a
// parameter never receives it.
type Args struct {
// Catalog is the name pattern of the catalog an object belongs to.
Catalog string
// Schema is the name pattern of the schema an object belongs to.
Schema string
// Parent is the name pattern of the object that contains this one, such as
// the table a column belongs to.
Parent string
// Name is the name pattern the object itself must match.
Name string
// ParentSchema is the name pattern of the schema of the parent, for a
// kind whose rows name a parent of their own, such as the parents that
// Inherits reads. Partition and PartitionSchema are the same for the
// partition that Partitions reads. See D201.
ParentSchema string
PartitionSchema string
// Types narrows a table to the kinds named, by Table.Type, such as table
// and view. Only Tables takes it, and every model's Tables does. It is
// bound as one string with the items joined by commas. See D138.
Types []string
// AccessMethod is the name pattern of an access method, which the
// operator classes and families of PostgreSQL take.
AccessMethod string
// Type is the name pattern of a type, which the operator classes and the
// operator families of PostgreSQL take, as the second pattern of psql's
// \dAc and \dAf does. An operator class matches it against its input type
// and an operator family against the types of its classes. See D309.
Type string
// Server is the name pattern of a foreign server, which the user mappings
// of PostgreSQL and the foreign tables of CrateDB take.
Server string
// Database is the name pattern of a database, which the role settings of
// PostgreSQL take.
Database string
// WithSystem includes the objects the database keeps for itself.
WithSystem bool
// WithIndexes adds the indexes that Partitions and Inherits leave out, so
// that a partitioned index has partitions and an index partition has a
// parent. See D262.
WithIndexes bool
// WithImplicit adds the tables that a publication of a schema or of
// every table offers without naming them, which PublicationTables reads.
// See D199 and D201.
WithImplicit bool
// WithTableInfo asks for the size, the row count and the options of a
// table from SVV_TABLE_INFO, which the Tables of Redshift reads only on
// request. Only a superuser or a user with SELECT on that view can read
// it, and a user without the right gets the error 42501 for the whole
// kind. Without it Size, Rows and Options are NULL. No other model takes
// it, so Query.All refuses it there and Query.Each leaves it out. See
// D232.
WithTableInfo bool
// ArgTypes narrows a function or an operator by the types of its
// arguments, as the type patterns of psql's \df and \do do. Each item is
// a name pattern for the type at that position, matched against the
// internal name of the type and the name that format_type gives, and the
// item - means that there is no argument at that position. For an operator
// the first item is the left operand and the second is the right one. An
// item can name a schema, such as pg_catalog.int4. A name that is not
// quoted must be in lower case, because the model reads the aliases int,
// float and decimal and the rest as psql does, and does not fold case.
// Only the Functions, Aggregates and Operators of PostgreSQL take it, so
// Query.All and Query.Each refuse it where it is not taken. See D272.
ArgTypes []string
}
// Map returns the arguments as a map, leaving out every field that is unset.
func (a Args) Map() map[string]any {
m := make(map[string]any, 12)
for name, v := range map[string]string{
"catalog": a.Catalog,
"schema": a.Schema,
"parent": a.Parent,
"name": a.Name,
"parent_schema": a.ParentSchema,
"partition_schema": a.PartitionSchema,
"access_method": a.AccessMethod,
"type": a.Type,
"server": a.Server,
"database": a.Database,
} {
if v != "" {
m[name] = v
}
}
if len(a.Types) != 0 {
m["types"] = a.Types
}
if a.WithSystem {
m["with_system"] = true
}
if a.WithIndexes {
m["indexes"] = true
}
if a.WithImplicit {
m["with_implicit"] = true
}
if a.WithTableInfo {
m["with_table_info"] = true
}
if len(a.ArgTypes) != 0 {
m["arg_types"] = a.ArgTypes
}
return m
}
// InList is the SQL condition that item is one of the items of list, where
// list is a string of items joined by commas, which is how a list parameter
// such as types is bound. It joins strings with ||, which most products
// accept. A model whose product joins strings another way writes the same
// condition itself. It does not handle an empty list, which means every item,
// because a product spells the empty string differently: Oracle and Exasol
// read it as NULL. See D138.
func InList(list, item string) string {
return `(',' || ` + list + ` || ',') LIKE ('%,' || ` + item + ` || ',%')`
}
// TypesParam is the parameter that narrows Tables to the kinds of relation
// named, by Table.Type. Every model's Tables takes it. See D138.
func TypesParam() Param {
return Param{
Name: "types",
Desc: "the types to list, as Table.Type spells them, such as table and view, and empty for every type",
Default: "",
}
}