Knex: ์—ฌ๋Ÿฌ ํ…Œ์ด๋ธ” ๊ฒฐํ•ฉ

์— ๋งŒ๋“  2014๋…„ 08์›” 28์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: knex/knex

๋‘˜ ์ด์ƒ์˜ ํ…Œ์ด๋ธ” ์กฐ์ธ์— ๋Œ€ํ•œ ๋ฌธ์„œ ๋‚˜ ์˜ˆ์ œ๊ฐ€ ํ‘œ์‹œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. .join ํ˜ธ์ถœ ๋งŒ ์—ฐ๊ฒฐํ•˜๋ฉด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๊นŒ?

question

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

knex์—์„œ ์—ฐ๊ฒฐ ์กฐ์ธ (๋‹ค์ค‘ ํ…Œ์ด๋ธ” ์กฐ์ธ)์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค๋ฉด :

var knex = require('./db')
knex('follow')
.join('users as u1', 'u1.id', 'follow.follower')
.join('users as u2', 'u2.id', 'follow.followee')
.select('u1.username as follower_name', 'u2.username as followee_name')
.then(follows => {
  follows.map((follow) => {
    console.log(follow.follower_name + " -> " + follow.followee_name);
  })
})

๋ชจ๋“  3 ๋Œ“๊ธ€

๋„ค

knex์—์„œ ์—ฐ๊ฒฐ ์กฐ์ธ (๋‹ค์ค‘ ํ…Œ์ด๋ธ” ์กฐ์ธ)์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค๋ฉด :

var knex = require('./db')
knex('follow')
.join('users as u1', 'u1.id', 'follow.follower')
.join('users as u2', 'u2.id', 'follow.followee')
.select('u1.username as follower_name', 'u2.username as followee_name')
.then(follows => {
  follows.map((follow) => {
    console.log(follow.follower_name + " -> " + follow.followee_name);
  })
})

@ guanzhou-zhao ์–ด๋–ป๊ฒŒ ์ด๊ฒƒ์„ lool์— ๋งคํ•‘ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

{
 "userId": 1,
 ...
 "followers": [
  {"userId": 2, ...},
  ...
]
}
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰