next-learn
next-learn copied to clipboard
Fixes invoice table re-ordering results on render and pagination due to order being random
Adds a unique value to the ORDER BY statement so that SQL behaves in a stable manner
This was causing unstable issues with pagination repeating data as you might get the same invoices on multiple pages with a non-unique ordering
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| next-learn-starter | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Dec 28, 2023 11:45pm |
| next-seo-starter | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Dec 28, 2023 11:45pm |
@esadler44 is attempting to deploy a commit to the Vercel Team on Vercel.
A member of the Team first needs to authorize it.
This fixes the issue of random order but breaks chapter 12 "You should see the new invoice at the top of the table." since the id is an auto-generated string.
I believe that this part of the code should be changed so it also includes time in the DB:
const date = new Date().toISOString().split('T')[0];
But I was not investigating it more deeply
After some investigation, I believe that here it should be:
const date = new Date().toISOString().replace('T', ' ').slice(0, 19);
and for creating the schema we could utilize this:
date TIMESTAMP NOT NULL
The idea is to store the time too. So you would be doing something like this:
INSERT INTO invoices (customer_id, amount, status, date)
VALUES
('cc27c14a-0acf-4f4a-a6c9-d45682c144b9', 100, 'paid', '2024-02-21 15:19:18'),
('cc27c14a-0acf-4f4a-a6c9-d45682c144b9', 100, 'paid', '2024-02-22 16:30:00'),
('cc27c14a-0acf-4f4a-a6c9-d45682c144b9', 100, 'paid', '2024-02-23 14:45:30');
WDYT?