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版)
持久化
|
145
(况且,恐怕它也未必总是最高效的数据类型)。当然可以修改数据库模式,使用一个数值
类型而不是
money
类型,但是不应该让前端选择左右模式设计。也可以干脆就使用
pg
返回
的格式化字符串,但那样的话就得修改所有代码,这些代码都是按
price
是一个数值类型
写的。此外,这种做法会对我们在前端进行的数值计算(比如说计算购物车中各项产品的
总价)产生不利影响。由于这些原因,我们倾向于从数据库取出时就把字符串解析为数字。
我们还获取了在表中以“扁平”形式存在的位置信息(
locat
ion
),把它变换成了更符合
JavaScript
风格的结构
。做这个变换是为了跟
MongoDB
的示例一致,也可以不做变换按原
本那样使用(或者修改
MongoDB
示例让它使用扁平结构)
。
关于
PostgreSQL
的使用,
还有最后一样东西需要学习,就是数据更新。那么下面就来完成
“度假产品上市通知”这个特性。
13.3.11
 新增数据
就像
MongoDB
的示例一样,我们也用“度假产品上市通知”来演示数据的新增。先把下
面的数据定义加入
db-init.js
的
createScript
字符串中:
CREATE TABLE IF NOT EXISTS vacation_in_season_listeners (
email varchar(200) NOT NULL,
sku varchar(20) NOT NULL,
PRIMARY KEY (email, sku)
);
别忘了,我们已经小心地把
db-init.js
写成非破坏性的了,因此可以随时运行它。那么就直 ...
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