2 Star 1 Fork 1

mosache/YFrame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tableReference.go 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
ヤ沒脩袮兲︶ 提交于 2023-07-17 12:07 . temp
package orm
type TableReference interface {
table()
}
// 普通表
type Table struct {
entity any
alias string
}
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,
}
}
func (t Table) table() {}
func (t Table) Join(target TableReference) *JoinBuilder {
return &JoinBuilder{
left: t,
right: target,
typ: " JOIN ",
}
}
func (t Table) LeftJoin(target TableReference) *JoinBuilder {
return &JoinBuilder{
left: t,
right: target,
typ: " LEFT JOIN ",
}
}
func (t Table) RightJoin(target TableReference) *JoinBuilder {
return &JoinBuilder{
left: t,
right: target,
typ: " RIGHT JOIN ",
}
}
// join
type Join struct {
left TableReference
right TableReference
typ string
on []Predicate
}
func (j Join) table() {}
func (j Join) Join(target TableReference) *JoinBuilder {
return &JoinBuilder{
left: j,
right: target,
typ: " JOIN ",
}
}
func (j Join) LeftJoin(target TableReference) *JoinBuilder {
return &JoinBuilder{
left: j,
right: target,
typ: " LEFT JOIN ",
}
}
func (j Join) RightJoin(target TableReference) *JoinBuilder {
return &JoinBuilder{
left: j,
right: target,
typ: " RIGHT JOIN ",
}
}
// /=====================================
func TableOf(entity any) Table {
return Table{entity: entity}
}
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,
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mosache/YFrame.git
git@gitee.com:mosache/YFrame.git
mosache
YFrame
YFrame
v0.1.68

搜索帮助