- Install postgres & nodejs
- Create the test database using the
./createdb.sh
script - Install the
npm_modules
for this project runningnpm install
- Run
npm run test
to get the program running (modify the user and password if needed) - Examine the typescript code under
server.ts
R.reduce((acc,x) => R.compose(R.flip(R.prepend)(acc), R.sum,R.map(R.add(1)))([x,...acc]), [0])([13, 28]);
I didn't understand the full code snippet. But, I got some points:
The anonymous function, call itself passing an array with two numbers.
Reduce is called passing the list of numbers and current iterator.
Compose function reverses functions composition, like right-to-left, the first becomes the last.
Add function is simple as a + b
; But used with R.map
apply the function to every element of the list.
The function R.sum
, Adds all the elements of a list supplied.
The functions R.prepend, R.flip
the mode of use, just made my head blow, i didn't get the point.
Never use SELECT * FROM ....
Ask only required fields.
Create some indexes becouse without indexes, every request to the DB would lead to a full scan of the entirety of the table to find results.
We could use cache to answer for some common queries .
PostgreSQL read-only replicas provide a great way to reduce the load on the main DB. It could be a great way to improve its speed.