在NodeJS中使用PostgreSQL JSON类型的最佳方法是什么

编程入门 行业动态 更新时间:2024-10-25 16:18:17
本文介绍了在NodeJS中使用PostgreSQL JSON类型的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在这里面临一些分析瘫痪.使用NodeJS进行数据库编程的选项太多了,我有点迷失了.

I am facing some analysis paralysis here. There are so many options for programming databases with NodeJS that I am a bit lost.

我正在使用Express构建API服务器,该服务器将与移动设备上的HTML5应用程序对话.我决定使用PostgreSQL,因为我的数据是非常相关的",而PostgreSQL新的JSON数据类型将使我的生活更加轻松.

I am building an API server using Express that will talk to a HTML5 app on mobile. I decided to use PostgreSQL because my data is "very relational" and PostgreSQL new JSON data type will make my life a lot easier.

不幸的是,我找不到利用新的JSON数据类型或公开它的PostgreSQL库.我考虑过使用 Sequelize 并拥有一个不错的ORM或使用原始pgsql模块滚动自己的东西

Unfortunately, I can't find any library for PostgreSQL taking advantage of the new JSON datatype or exposing it. I thought about using Sequelize and having a nice ORM or rolling my own stuff by using the raw pgsql module.

有人可以提供线索吗?我会在一些NodeJS stackexchange上问这个问题,但我认为我们没有这么具体的问题.

Can someone shed a clue? I'd ask this on some NodeJS stackexchange but I don't think we have one as specific as this.

推荐答案

我喜欢 github. com/brianc/node-postgres .它是积极开发的,只是一个很好的薄层.

I like github/brianc/node-postgres. It's actively developed, and just a nice thin layer.

要在准备好的查询中使用json类型,只需JSON.stringify您要存储为json的任何内容(这就是postgres想要的方式).

To use the json types in a prepared query, just JSON.stringify whatever you are trying to store as json (that's how postgres wants it anyway).

更多推荐

在NodeJS中使用PostgreSQL JSON类型的最佳方法是什么

本文发布于:2023-10-16 16:53:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   方法   NodeJS   PostgreSQL   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!