Sequelize 基本認識

# Sequelize 基本認識 ## 1. Timestamps https://sequelize.org/v5/manual/models-definition.html#timestamps ## 2. Database synchronization https://sequelize.org/v5/manual/models-definition.html#database-synchronization 建議不要直接使用於正式環境,應該在測試建立後,取得對應 sql 碼後,在正式上線時,手動更新正式 DB 資料結構 **2.1** 使用 sync 建立的 table name 會加上 s **2.2** 正常情況下,對 table 操作盡可能還是已手動為主,雖然 Sequelize 有提供一些操作,但減少使用比較安全,當手動操作完畢後,應該把 raw sql 匯出備份,正式上線時,再手動更新 ## 3. Modeling a table 建立 https://sequelize.org/v5/manual/getting-started.html ``` const Model = Sequelize.Model; class User extends Model {} User.init({ ``` 建議使用 ``` sequelize.define:‘user’, { // attributes firstName: { ``` 原因,看起來簡單多了 3.1 Model 操作 https://sequelize.org/v5/manual/models-usage.html ## 4. Raw queries https://sequelize.org/v5/manual/raw-queries.html 基本當join比較複雜建議使用,因為清楚、效率可控,或更複雜的 sub sql 都可以進行,避免 ORM 處理不當,造成效能大幅下降 ...

2020-04-09 · 1 min · 89 words · Me

西方式傲慢

西方式傲慢 https://youtu.be/-3lqr6Ys_zQ?t=697 中國為西方贏得時間,西方卻浪費了它 張彥 https://cn.nytimes.com/opinion/20200314/china-response-china/zh-hant/ 普立茲獎 張彥 https://zh.wikipedia.org/zh-tw/%E5%BC%A0%E5%BD%A6_(%E7%BE%8E%E5%9B%BD%E8%AE%B0%E8%80%85) 連 柳葉刀的主編 中國傳遞了非常清淅的訊息,可是我們浪費了整整2個月 https://news.sina.com.tw/article/20200401/34733366.html https://www.facebook.com/watch/?v=538201007134058

2020-04-06 · 1 min · 13 words · Me

[轉]Go 交叉編譯

https://ithelp.ithome.com.tw/articles/10225188 在Windows上編譯 To MacOs SET CGO_ENABLED=0 SET GOOS=darwin SET GOARCH=amd64 go build main.go To Linux SET CGO_ENABLED=0 SET GOOS=linux SET GOARCH=amd64 go build main.go To Windows ??? go build main.go 在Linux上編譯 CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

2020-03-26 · 1 min · 49 words · Me

不可思議抗癌歷程 林百里求診中國御醫兩度重生

https://youtu.be/8dvbY0jTlUI?t=1600

2020-03-23 · 1 min · word · Me

javascript firestore object sort

const bookListsQuery = await modules.firestore.collection('books') .get(); const sortedObj = Object.values(bookListsQuery.docs).sort(function(a, b){ console.log('a %s b %s', a.data().order, b.data().order) return Number(a.data().order) > Number(b.data().order); }); sortedObj.forEach(function(doc){ console.log(doc.data()) }); other way object use map to array, then it sorted. const bookListsQuery = await modules.firestore.collection('books') .get(); const sortedArr = bookListsQuery.docs.map(function (doc) { // 轉換成array return doc.data() }); sortedArr.sort(function compare(a, b) { return a.order > b.order; // 升 小->大 }); sortedArr.forEach(function(data){ console.log(data.data()) }) ========== Sorting multiple object properties with JavaScript https://bithacker.dev/javascript-object-multi-property-sort ...

2020-03-19 · 1 min · 163 words · Me