[英]PRISMA: How can i select only first string from string array
我正在寻找在 Prisma ORM 中获取字符串数组的确切元素的解决方案,在我的情况下,我只想使用段落数组的第一个元素来在前面呈现简短的文章描述。
那是我的文章 model
model articles {
id BigInt @id @default(autoincrement())
articleId Int @unique
scrapedAt DateTime @default(now())
timeString String
time BigInt
title String
url String
img String
paragraphs String[]
}
假设我们像下面的代码一样创建文章
const result = await prisma.articles.create({
data:{
articleId: 1,
timeString: "25082022",
time: 25082022,
title: "First Article title",
url: "First Url",
img: "Image URL",
paragraphs: ["First Paragraph for article", "second paragraph"]
}
})
然后我们可以查询段落并从结果集中选择第一个
const result = await prisma.articles.findFirst({
where:{
id: 1n
},
select:{
paragraphs: true
}
})
console.log(result.paragraphs[0])
查询以这种形式返回结果
{ paragraphs: [ 'First Paragrah for article', 'second paragraph' ] }
那么记录result.paragraphs[0]
的结果是
Output
First Paragraph for article
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.