sequelize 資料庫操作

2021-09-29 18:20:09 字數 3360 閱讀 9048

require

('../models'

).demo

async

function

register

(params)

return

await demo.

create

(params)

.then

(result=>)}

where:條件 offset:開始位置 limit : 查詢條數

async

function

find

(params)).

then

(result=>})

}

async

function

get(params)})

.then

(result=>

)}

async

function

name

(params),}

).then

(result=>

)}

***.sequelize.query(sql,).then()

const util =

require

('util');

async

function

findname

(name)).

then

(result=>

)}

這裡需要使用到op,他從***x.sequelize.op中可以獲取,在op.like,

return

await demo.

findandcountall(}

, offset:

(params.page-1)

*params.limit,

limit:

parseint

(params.limit)})

.then

(result=>

})

async

function

del(params)})

.then

(result =>

)}

async

function

find()

}).then

(result =>

)}

return

await test.

count(,

test.sequelize.or(

},})

)}).

then

(result=>

)//相當於 : select * from test where typeid = 1 and ( title like "%標題%" or name like "%名稱%")

var user = sequelize.

define

('user',,

);

const content =

require

("../models"

).content;

const content_category =

require

("../models"

).content_category;

return

await content.

findone(,

include:

[ attributes:

["id"]}

]}).

then

(result=>

)

return

await content_category.

findall(}

).then

(result=>

)//-----------------------------------------

return

await content_category.

findall()

.then

(result=>

)

乙個訂單對應乙個訂單收貨位址位址

order訂單表model

order.

hasone

(models.order_shipping,

);

order_shipping訂單收貨位址表model

order_shipping.

belongsto

(models.order,

)

sequelize文件鏈結說明該功能:

//示例1

post.

findall()

;// select ... from "post" as "post" where char_length("content") = 7

//示例2

vehicle.

findall(,

sequelize.

where

( sequelize.

cast

('vehicle.odometer'

,'decimal'),

))})

;// select ... from "vehicle" as "vehicle" where vin_id = 'vin_id' and (cast('vehicle.odometer' as decimal) >= -27 and cast('vehicle.odometer') as decimal < -8)

//示例3

post.

findall(}

,,sequelize.

where

(sequelize.fn(

'char_length'

, sequelize.

col(

'content'))

,)]}

]}})

;//select ... from "posts" as "post" where ( char_length("content") = 7 or "post"."content" like 'hello%' or ( "post"."status" = 'draft' and char_length("content") > 10 ))

sequelize資料庫操作

1.create新增操作 require models demo async function register params return await demo.create params then result 2.分頁查詢 findandcountall where 條件 offset 開始位...

使用sequelize對資料庫進行增刪改查

首先我們需要在自己的資料夾下執行一下cmd npm init y y 的主要目的是跳過配置一系列的package.json 其次我們需要安裝兩個sequelize和mysql2 yarn add sequelize mysql2 s 或者npm install sequelize mysql2 s ...

資料庫(庫操作)

information schema 虛擬庫,不占用磁碟空間,儲存的是資料庫啟動後的一些引數,如使用者表資訊 列資訊 許可權資訊 字元資訊等 performance schema mysql 5.5開始新增乙個資料庫 主要用於收集資料庫伺服器效能引數,記錄處理查詢請求時發生的各種事件 鎖等現象 my...