Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
144
|
第
13
章
我们还要做出一个关于
Vacation
模型的决定。回忆一下,我们创建模型的时候,数据库模
式使用的是小写下划线形式,但是我们的
JavaScript
代码用的都是驼峰式
。大体来讲,这
里有
3
个选择。
•
把数据库模式重构为驼峰式。这样做会让
SQL
更难看
,因为必须要记得正确地引用属
性名。
•
在
JavaScript
中使用小写下划线形式。
这远不是理想做法,因为我们喜欢符合标准的代码。
•
在数据库中使用小写下划线形式,在
JavaScript
中转换为驼峰式
。这样的话我们要做的
工作会多一些,但
SQL
和
JavaScript
都不用改动。
幸运的是,第三个选择可以自动完成。我们与其自己写函数做转换,不如依靠一个流行的
工具库
Lodash
,它使得这件事极为容易。只需运行
npm install lodash
即可完成安装。
目前我们的数据库需求还比较简单,需要做的只是查出所有可用的度假产品套餐。因此,
db.js
文件大概是这样的(版本库的
ch13/01-postgres/db.js
):
const { Pool } = require('pg')
const _ = require('lodash')
const credentials = require('./credentials')
const { connectionString } = credentials.postgres
const pool = new Pool({ connectionString })
module.exports ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099