-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d07f000
commit 9bff4ba
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package eorm | ||
|
||
type TableReference interface { | ||
} | ||
|
||
// Table 普通表 | ||
type Table struct { | ||
entity any | ||
alias string | ||
} | ||
|
||
func TableOf(entity any) Table { | ||
return Table{ | ||
entity: entity, | ||
} | ||
} | ||
|
||
func (t Table) Join(right TableReference) *JoinBuilder { | ||
return &JoinBuilder{ | ||
left: t, | ||
right: right, | ||
typ: "JOIN", | ||
} | ||
} | ||
|
||
func (t Table) LeftJoin(right TableReference) *JoinBuilder { | ||
return &JoinBuilder{ | ||
left: t, | ||
right: right, | ||
typ: "LEFT JOIN", | ||
} | ||
} | ||
|
||
func (t Table) RightJoin(right TableReference) *JoinBuilder { | ||
return &JoinBuilder{ | ||
left: t, | ||
right: right, | ||
typ: "RIGHT JOIN", | ||
} | ||
} | ||
|
||
func (t Table) As(alias string) Table { | ||
return Table{ | ||
entity: t.entity, | ||
alias: alias, | ||
} | ||
} | ||
|
||
func (t Table) C(name string) Column { | ||
return Column{ | ||
name: name, | ||
table: t, | ||
} | ||
} | ||
|
||
type Join struct { | ||
left TableReference | ||
right TableReference | ||
on []Predicate | ||
using []string | ||
typ string | ||
} | ||
|
||
func (j Join) Join(reference TableReference) *JoinBuilder { | ||
return &JoinBuilder{ | ||
left: j, | ||
right: reference, | ||
typ: "JOIN", | ||
} | ||
} | ||
|
||
func (j Join) LeftJoin(reference TableReference) *JoinBuilder { | ||
return &JoinBuilder{ | ||
left: j, | ||
right: reference, | ||
typ: "LEFT JOIN", | ||
} | ||
} | ||
|
||
func (j Join) RightJoin(reference TableReference) *JoinBuilder { | ||
return &JoinBuilder{ | ||
left: j, | ||
right: reference, | ||
typ: "RIGHT JOIN", | ||
} | ||
} | ||
|
||
type JoinBuilder struct { | ||
left TableReference | ||
right TableReference | ||
typ string | ||
} | ||
|
||
func (j *JoinBuilder) On(ps ...Predicate) Join { | ||
return Join{ | ||
left: j.left, | ||
right: j.right, | ||
typ: j.typ, | ||
on: ps, | ||
} | ||
} | ||
|
||
func (j *JoinBuilder) Using(cols ...string) Join { | ||
return Join{ | ||
left: j.left, | ||
right: j.right, | ||
typ: j.typ, | ||
using: cols, | ||
} | ||
} |