Best practice when inserting many-to-many relationships in transactions using ON DUPLICATE KEY UPDATE with bookshelves (knex)

Good, so I'm working on a personal project with which you can “browse” the lists. The user can find the movie they heard using the public API (TheMovieDB) and add it to their watchlist. Whenever a movie is added, I save the data in a database. I use the following tables (excluding columns that are not relevant to the question):

of users

  • ID

movies

  • ID (PK)
  • tmdbID (unique)

movies_users

  • ID (PK)
  • movie_ID (FK link identifier in the movie table)
  • user_ID (identifier of FK links in the user table)

genres

  • ID (PK)
  • Name (unique)

genres_movies

  • ID (PK)
  • genre_ID (FK link identifier in the genre table)
  • movie_ID (FK link identifier in the movie table)

MariaDB, ON DUPLICATE KEY UPDATE, , , , - , movies_users. , .

NodeJS BookshelfJS.

SQL, , . , Promises. , : http://codeshare.io/BPWDV.

, ? knex.raw(http://knexjs.org/#Raw-Queries), ON DUPLICATE KEY UPDATE. , :

  • ,
  • , , movies_users. , , .
  • movies_users
  • . , , , . , , .
  • , genres_movies

, , . promises . , , ?

act_movies, , ( Promise.map).

, , : , , , , ?

+4

Source: https://habr.com/ru/post/1606080/


All Articles