Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions live-demo/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ if (import.meta.url === `file://${process.argv[1]}`) {
const db = admin.resource('aparts').dataConnector.client;
const days = req.body.days || 7;
const apartsByDays = await db.prepare(
`SELECT
`SELECT
strftime('%Y-%m-%d', created_at) as day,
COUNT(*) as count
FROM apartments
GROUP BY day
ORDER BY day DESC
LIMIT ?;
`
ORDER BY day ASC
LIMIT ?;`
).all(days);


const totalAparts = apartsByDays.reduce((acc: number, { count }: { count:number }) => acc + count, 0);

// add listed, unlisted, listedPrice, unlistedPrice
Expand All @@ -170,11 +170,11 @@ if (import.meta.url === `file://${process.argv[1]}`) {
SUM((1 - listed) * price) as unlistedPrice
FROM apartments
GROUP BY day
ORDER BY day DESC
LIMIT ?;
`
ORDER BY day ASC
LIMIT ?;`
).all(days);


const apartsCountsByRooms = await db.prepare(
`SELECT
number_of_rooms,
Expand Down Expand Up @@ -204,16 +204,16 @@ if (import.meta.url === `file://${process.argv[1]}`) {
).get();

const listedVsUnlistedPriceByDays = await db.prepare(
`SELECT
`SELECT
strftime('%Y-%m-%d', created_at) as day,
SUM(listed * price) as listedPrice,
SUM((1 - listed) * price) as unlistedPrice
FROM apartments
GROUP BY day
ORDER BY day DESC
LIMIT ?;
`
ORDER BY day ASC
LIMIT ?;`
).all(days);


const totalListedPrice = Math.round(listedVsUnlistedByDays.reduce((
acc: number, { listedPrice }: { listedPrice:number }
Expand Down