GoForum › 🌐 V2EX
这样的 nql,大家能接受吗?
sskycn ·
2026-09-20 08:53 ·
0 次点赞 · 4 条回复
nql 1;
query GetUser(id: UserId) {
from users as u
where u.id == $id
select {
id: u.id,
name: u.name,
nickname: u.nickname
}
}
query TeamMembers(team: TeamId) {
from memberships as m
join users as u
on m.user_id == u.id
where m.team_id == $team
select {
user_id: u.id,
name: u.name,
role: m.role
}
order {
u.name asc
}
}
command CreateUser(
id: UserId,
team: TeamId,
name: Text,
nickname: Text?
) {
insert users {
id: $id,
team_id: $team,
name: $name,
nickname: $nickname
}
}
command RenameUser(
id: UserId,
name: Text
) {
update users
set {
name = $name
}
where id == $id
}
command DeleteUser(id: UserId) {
delete users
where id == $id
}
4 条回复
复杂的查询大概是这样子写:
query CustomerDetail(customer: CustomerId) {
from customers as c
where c.id == $customer
select {
id: c.id,
name: c.name,
addresses: many {
from addresses as a
where a.customer_id == c.id
select {
id: a.id,
city: a.city,
address: a.address
}
},
orders: many {
from orders as o
where o.customer_id == c.id
select {
id: o.id,
created_at: o.created_at,
total: o.total,
items: many {
from order_items as oi
join products as p
on p.id == oi.product_id
where oi.order_id == o.id
select {
product: {
id: p.id,
name: p.name
},
quantity: oi.quantity,
price: oi.price
}
}
}
order {
o.created_at desc
}
limit 20
}
}
}
添加回复
你还需要 登录
后发表回复
改个编写顺序…也没减少字符…也没看出来动态 sql…对我来说用处不大…不如 mybatis hibernate…