在NodeJS中使用PostgreSQL JSON类型的最佳方法是什么 [英] What is the best way to use PostgreSQL JSON types with NodeJS

查看:110
本文介绍了在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.

推荐答案

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

I like https://github.com/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类型的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆