[Sequelize] Sequelize findAndCountAll ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ ์‹œ count๊ฐ€ ์˜ˆ์ƒ๋ณด๋‹ค ๋” ๋งŽ์ด ์นด์šดํŒ… ๋˜๋Š” ๋ฌธ์ œ ํ•ด๊ฒฐ
ยท
Backend/Sequelize
๐Ÿ”ฅ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ getBoards ํ•จ์ˆ˜๋Š” ์นดํ…Œ๊ณ ๋ฆฌ์— ํ•ด๋‹นํ•˜๋Š” ๊ฒŒ์‹œ๊ธ€ ์ „์ฒด๋ฅผ ํŽ˜์ด์ง• ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ํ•จ์ˆ˜๋‹ค. (๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ๊ด€๋ จ ์—†๋Š” ์ฝ”๋“œ ์ผ๋ถ€ ์ƒ๋žต) /* ํŽ˜์ด์ง• ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ํ•จ์ˆ˜๋“ค(์ฐธ๊ณ ์šฉ) const getPagination = (page, size) => { const limit = size ? +size : 10; // ๊ฐ€์ ธ์˜ฌ ๋ฐ์ดํ„ฐ ์–‘ const offset = page ? page * limit : 0; // ๊ฐ€์ ธ์˜ฌ ๋ฐ์ดํ„ฐ์˜ ์ดˆ๊ธฐ ์œ„์น˜๊ฐ’ return { limit, offset }; }; const getPagingData = (data, page, limit) => { // count: where ์ ˆ, ์—ฐ๊ฒฐ ๊ด€๊ณ„ ๋“ฑ์˜ ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜๋Š” ๋ ˆ์ฝ”๋“œ์˜ ์ „์ฒด ๊ฐœ์ˆ˜ // rows: where ์ ˆ, ์—ฐ๊ฒฐ ๊ด€..
_์„ฑํ˜ธ_
'Sequelize ORM' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก