memcode icon indicating copy to clipboard operation
memcode copied to clipboard

Backend: migrate legacy endpoint structure to new endpoint structure

Open lakesare opened this issue 4 years ago • 5 comments

Migrating the backend endpoints of this form: https://github.com/lakesare/memcode/blob/master/backend/api/CourseApi/index.js#L10 into endpoints of this form: https://github.com/lakesare/memcode/blob/master/backend/api/CourseApi/rate.js is always a #todo.

It's fine to PR just a few endpoints migrated.

If migrating to knex is too hard (e.g. SQL query is more easily written in raw SQL), - it’s fine to leave pg-promise.

lakesare avatar Mar 29 '20 21:03 lakesare

@lakesare What is your thoughts on this: https://medium.com/@gajus/stop-using-knex-js-and-earn-30-bf410349856c

anandvenkat4 avatar Apr 01 '20 07:04 anandvenkat4

@anandvenkat4, I think that's the author of slonik 🙃 I think we can see the value of knex for ourselves by comparing the before (raw sql with pg-promise) / after code (with knex) of any controller. Fyi pg-promise is very close to slonik syntax-wise, - you also write raw SQL.

lakesare avatar Apr 01 '20 07:04 lakesare

Got it :)

anandvenkat4 avatar Apr 01 '20 07:04 anandvenkat4

To give a flavour of my changes and to align with what is expected, I am sending you a PR which replaces 'countAllPublic' to a knex like syntax. Please let me know your comments.

anandvenkat4 avatar Apr 01 '20 10:04 anandvenkat4

@anandvenkat4, great PR 👍 We should also be moving these routes into separate files (see /CourseApi/rate.js).

And in the future, - if some query is too complex in SQL (see the getCoursesWithStats()), - it can be better to leave it as such. Sometimes it’s indeed easier to read the raw SQL.

lakesare avatar Apr 01 '20 11:04 lakesare