Skip to content

Commit bbdf83e

Browse files
some ideas and minor fixes
1 parent 9c14b56 commit bbdf83e

3 files changed

Lines changed: 69 additions & 8 deletions

File tree

client/mock/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,20 @@ func WitchPre(fn func(method string, args map[string]any) error) MockOption {
9090

9191
// --- Client implementation template ---
9292

93-
// func (m *Client) <MethodUsername>(ctx context.Context, <Args>) <ReturnValues> {
93+
// func (m *Client) <MethodName>(ctx context.Context, <Args>) <ReturnValues> {
9494
// if m.Pre != nil {
95-
// err := m.Pre("<MethodUsername>", map[string]any{"<ArgUsername>": <ArgValue>, ...})
95+
// err := m.Pre("<MethodName>", map[string]any{"<ArgUsername>": <ArgValue>, ...})
9696
// if err != nil {
9797
// return <ReturnValue?>, err
9898
// }
9999
// }
100-
// if m.Overwrites.<MethodUsername> != nil {
101-
// return m.Overwrites.<MethodUsername>(ctx, <Args>)
100+
// if m.Overwrites.<MethodName> != nil {
101+
// return m.Overwrites.<MethodName>(ctx, <Args>)
102102
// }
103103
// else if m.BaseClient != nil {
104-
// return m.BaseClient.<MethodUsername>(ctx, <Args>)
104+
// return m.BaseClient.<MethodName>(ctx, <Args>)
105105
// }
106-
// panic("Client.<MethodUsername> not implemented")
106+
// panic("Client.<MethodName> not implemented")
107107
// }
108108

109109
// --- Lifecycle & Initialization ---

tags/expr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ func (e ValueExpr) hash() string {
138138
func (e AndExpr) hash() string {
139139
hashes := slicest.Map(e.Exprs, func(e Expr) string { return e.hash() })
140140
slices.Sort(hashes)
141-
return string(exprAnd) + strings.Join(hashes, string(exprHashDelimiter))
141+
return string(exprAnd) + string(exprBracesOpen) + strings.Join(hashes, string(exprHashDelimiter)) + string(exprBracesClose)
142142
}
143143
func (e OrExpr) hash() string {
144144
hashes := slicest.Map(e.Exprs, func(e Expr) string { return e.hash() })
145145
slices.Sort(hashes)
146-
return string(exprOr) + strings.Join(hashes, string(exprHashDelimiter))
146+
return string(exprOr) + string(exprBracesOpen) + strings.Join(hashes, string(exprHashDelimiter)) + string(exprBracesClose)
147147
}
148148
func (e NotExpr) hash() string {
149149
return exprNot + string(exprBracesOpen) + e.Expr.hash() + string(exprBracesClose)

tags/multi_table_tags_bun.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Tag Matcher
2+
"(user1 | user2) & !hagebau"
3+
4+
# Tabellen
5+
public_keys:
6+
- id
7+
- key
8+
9+
tags_to_pk:
10+
- pk_id
11+
- tag_id
12+
13+
tags
14+
- id
15+
- name
16+
17+
# SQL Request
18+
```sql
19+
SELECT DISTINCT pk.*
20+
FROM public_keys AS pk
21+
JOIN tags_to_pk AS ttpk ON ttpk.pk_id = pk.id
22+
JOIN tags AS t ON t.id = ttpk.tag_id
23+
WHERE pk.id IN (
24+
SELECT ttpk1.pk_id
25+
FROM tags_to_pk AS ttpk1
26+
JOIN tags AS t1 ON t1.id = ttpk1.tag_id
27+
WHERE t1.name IN ('user1', 'user2')
28+
)
29+
AND pk.id NOT IN (
30+
SELECT ttpk2.pk_id
31+
FROM tags_to_pk AS ttpk2
32+
JOIN tags AS t2 ON t2.id = ttpk2.tag_id
33+
WHERE t2.name = 'hagebau'
34+
);
35+
```
36+
37+
# Bun implementation
38+
```go
39+
var publicKeys []PublicKey
40+
41+
subInclude := db.NewSelect().
42+
Model((*TagsToPk)(nil)).
43+
Column("pk_id").
44+
Join("JOIN tags AS t1 ON t1.id = tags_to_pk.tag_id").
45+
Where("t1.name IN (?)", bun.In([]string{"user1", "user2"}))
46+
47+
subExclude := db.NewSelect().
48+
Model((*TagsToPk)(nil)).
49+
Column("pk_id").
50+
Join("JOIN tags AS t2 ON t2.id = tags_to_pk.tag_id").
51+
Where("t2.name = ?", "hagebau")
52+
53+
err := db.NewSelect().
54+
Model(&publicKeys).
55+
Distinct().
56+
Join("JOIN tags_to_pk AS ttpk ON ttpk.pk_id = public_key.id").
57+
Join("JOIN tags AS t ON t.id = ttpk.tag_id").
58+
Where("public_key.id IN (?)", subInclude).
59+
Where("public_key.id NOT IN (?)", subExclude).
60+
Scan(ctx)
61+
```

0 commit comments

Comments
 (0)