Node.js Drizzle orderBy 升序、降序、联合排序

Drizzle Node.js About 600 words

orderBy()

使用typeof$inferSelect提取表结构的类型。

升序

orderBy(columnName)等价于orderBy(asc(columnName))

const postList: Array<Post> = await db.select()
    .from(posts)
    .orderBy(posts.id)
    .limit(10);

降序

orderBy(desc(columnName))

import {desc} from "drizzle-orm";

const postList: Array<Post> = await db.select()
    .from(posts)
    .orderBy(desc(posts.id))
    .limit(10);

联合排序

import {desc, asc} from "drizzle-orm";

const postList: Array<Post> = await db.select()
    .from(posts)
    .orderBy(desc(posts.createTime), asc(posts.id))
    .limit(10);

官方文档

https://orm.drizzle.team/docs/select#order-by

Views: 19 · Posted: 2025-10-10

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Today In History
Browsing Refresh