这样的 nql,大家能接受吗?

1 天前
 sskycn
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
}
2699 次点击
所在节点    数据库
13 条回复
Aruforce
1 天前
改个编写顺序…也没减少字符…也没看出来动态 sql…对我来说用处不大…不如 mybatis hibernate…
yangg
1 天前
看着不错,
复杂嵌套的呢?
sskycn
1 天前
复杂的查询大概是这样子写:

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
}
}
}
diudiuu
1 天前
老哥还在坚持手搓,是之前写 db 的那个吗
sskycn
1 天前
@diudiuu 是,现在在给 https://github.com/sskycn/netbadb 设计新的查询语言。

不兼容 pg,mysql 了,走一条特立独行的路。
diudiuu
1 天前
@sskycn #5 先关注了,看着写法理解起来还算简单
cowcomic
1 天前
@sskycn 是直接代替 SQL 么,还是给 SQL 包层壳?
sskycn
1 天前
不是代替 SQL ,也不是给 SQL 包层壳。

这是给 NetbaDB 专门设计的一种脚本语言,#1 说的对,还是太复杂了,我还在思考别的方案。
gopheryi
1 天前
有 ai 之后真的还需要这些吗,把 skill 写好让 ai 写 ,小众语言感觉会愈来愈少人用
dacapoday
1 天前
有没有兴趣谈谈背后的关系模型建模, 比如 schemaless, 全文搜索/向量搜索 与 关系模型 的结合.
表层的句法在 AI 时代已经没有优化的意义了.
sskycn
23 小时 57 分钟前
NetbaDB 现在的基本路径是:

Canonical Schema → typed HIR → Typed Relational IR → Planner → Executor → Storage

Heap / LSM 是 authoritative storage ;现在的 Columnar 也是作为 derived projection 存在,而不是另一套数据库模型.

没打算做 schemaless ,而是从用户程序的静态类型定义中生成/推导出来。

强类型和自适应是这个数据库的目标。
gefangshuai
17 小时 37 分钟前
老哥很强,但是现在用 AI 已经不关注这些了。
rev1si0n
16 小时 8 分钟前
@gefangshuai 是的,我也觉得在 AI 这个环境下,这些已经没有什么优势了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1243238

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX