Skip to content

Instantly share code, notes, and snippets.

@katychuang
Last active January 26, 2025 21:15
Show Gist options
  • Save katychuang/ef6b01bf446c24a07cff9750b33717bf to your computer and use it in GitHub Desktop.
Save katychuang/ef6b01bf446c24a07cff9750b33717bf to your computer and use it in GitHub Desktop.
SQLite
See makefile for execution
Artist Song
Shaboozey A Bar Song (Tipsy)
Post Malone Featuring Morgan Wallen I Had Some Help
Sabrina Carpenter Espresso
Sabrina Carpenter Please Please Please
Sabrina Carpenter Taste
Lady Gaga & Bruno Mars Die With A Smile
Billie Eilish Birds Of A Feather
Chappell Roan Good Luck, Babe!
Teddy Swims Lose Control
Kendrick Lamar Not Like Us
Tommy Richman Million Dollar Baby
Hozier Too Sweet
Benson Boone Beautiful Things
Luke Combs Ain't No Love In Oklahoma
Sabrina Carpenter Bed Chem
Morgan Wallen Featuring ERNEST Cowgirls
Marshmello & Kane Brown Miles On It
Chappell Roan Hot To Go!
Morgan Wallen Lies Lies Lies
Zach Bryan Pink Skies
Dasha Austin
Sabrina Carpenter Good Graces
Jelly Roll I Am Not Okay
Jordan Adetunji Kehlani
SZA Saturn
Post Malone Featuring Blake Shelton Pour Me A Drink
Future, Metro Boomin & Kendrick Lamar Like That
Jimin Who
Sabrina Carpenter Juno
Chappell Roan Pink Pony Club
Hanumankind X Kalmi Big Dawgs
Taylor Swift I Can Do It With A Broken Heart
Zach Bryan 28
Benson Boone Slow It Down
GloRilla TGIF
Teddy Swims The Door
Karol G Si Antes Te Hubiera Conocido
GloRilla & Megan Thee Stallion Wanna Be
Noah Kahan Stick Season
Post Malone Featuring Luke Combs Guy For That
Ella Langley Featuring Riley Green You Look Like You Love Me
Sabrina Carpenter Sharpest Tool
Sabrina Carpenter Coincidence
Eminem Houdini
Myles Smith Stargazing
Koe Wetzel & Jessie Murph High Road
Charli xcx 360
Charli xcx Featuring Billie Eilish Guess
Billie Eilish Wildflower
Sabrina Carpenter Slim Pickins
Chappell Roan Red Wine Supernova
Megan Thee Stallion Featuring Yuki Chiba Mamushi
Gunna One Of Wun
Cody Johnson Dirt Cheap
Moneybagg Yo Featuring Morgan Wallen Whiskey Whiskey
Dustin Lynch Featuring Jelly Roll Chevrolet
Post Malone Featuring Jelly Roll Losers
Real Boston Richey Help Me
Thomas Rhett Beautiful As You
Drake No Face
Taylor Swift Featuring Post Malone Fortnight
Sabrina Carpenter Dumb & Poetic
Sabrina Carpenter Don't Smile
The Kid LAROI Nights Like This
Charli xcx Apple
FloyyMenor X Cris Mj Gata Only
Gracie Abrams I Love You, I'm Sorry
Gigi Perez Sailor Song
Drake Circadian Rhythm
Peso Pluma & Neton Vega La Patrulla
Central Cee & Lil Baby BAND4BAND
mgk & Jelly Roll Lonely Road
Ariana Grande The Boy Is Mine
Drake, Young Thug & 21 Savage It's Up
Chris Stapleton Think I'm In Love With You
LE SSERAFIM Crazy
Sabrina Carpenter Lie To Girls
Tucker Wetmore Wind Up Missin' You
Billie Eilish Lunch
Luke Bryan Love You, Miss You, Mean It
Chappell Roan Casual
Fuerza Regida Nel
Luis R Conriquez x Neton Vega Si No Quieres No
A$AP Rocky Tailor Swif
Megan Moroney Am I Okay?
Mark Ambor Belong Together
Billie Eilish Chihiro
Sexyy Red & Drake U My Everything
Chappell Roan Femininomenon
Tommy Richman Devil Is A Lie
Chase Matthew Love You Again
Post Malone Featuring Tim McGraw Wrong Ones
Benson Boone Pretty Slowly
Chris Young Young Love & Saturday Nights
Tinashe Nasty
Gracie Abrams Close To You
21 Savage & Summer Walker Prove It
Mustard & Travis Scott Parking Lot
Lil Yachty & Veeze Sorry Not Sorry
Post Malone Featuring Chris Stapleton California Sober
Artist Song
Shaboozey A Bar Song (Tipsy)
Billie Eilish Birds Of A Feather
Sabrina Carpenter Espresso
Lady Gaga & Bruno Mars Die With A Smile
Post Malone Featuring Morgan Wallen I Had Some Help
Teddy Swims Lose Control
Chappell Roan Good Luck, Babe!
Sabrina Carpenter Taste
Benson Boone Beautiful Things
Sabrina Carpenter Please Please Please
Kendrick Lamar Not Like Us
Hozier Too Sweet
The Weeknd & Playboi Carti Timeless
Jelly Roll I Am Not Okay
Tommy Richman Million Dollar Baby
Rod Wave 25
Morgan Wallen Lies Lies Lies
Chappell Roan Hot To Go!
Gracie Abrams I Love You, I'm Sorry
Marshmello & Kane Brown Miles On It
Morgan Wallen Featuring ERNEST Cowgirls
GloRilla TGIF
Luke Combs Ain't No Love In Oklahoma
Zach Bryan Pink Skies
Dasha Austin
Sabrina Carpenter Bed Chem
Billie Eilish Wildflower
Gigi Perez Sailor Song
Teddy Swims The Door
Myles Smith Stargazing
GloRilla & Sexyy Red Whatchu Kno About Me
Jimin Who
Ella Langley Featuring Riley Green You Look Like You Love Me
Jordan Adetunji Kehlani
Rod Wave Last Lap
Charli xcx Featuring Ariana Grande Sympathy Is A Knife
Taylor Swift I Can Do It With A Broken Heart
SZA Saturn
Chappell Roan Pink Pony Club
Post Malone Featuring Blake Shelton Pour Me A Drink
Charli xcx 360
Tate McRae It's Ok I'm Ok
Koe Wetzel & Jessie Murph High Road
Rod Wave Federal Nightmares
Future, Metro Boomin & Kendrick Lamar Like That
Rod Wave Angel With An Attitude
Karol G Si Antes Te Hubiera Conocido
GloRilla Hollon
Rod Wave Fall Fast In Love
Rod Wave Featuring Lil Yachty & Lil Baby F**k Fame
Rod Wave Passport Junkie
The Weeknd Dancing In The Flames
Real Boston Richey Help Me
Rod Wave Never Mind
Charli xcx Featuring Billie Eilish Guess
Tucker Wetmore Wind Up Missin' You
Rod Wave Turtle Race
NLE Choppa & 41 Or What?
Zach Bryan 28
Peso Pluma & Neton Vega La Patrulla
Sabrina Carpenter Juno
Charli xcx Apple
Rod Wave Apply Pressure
KSI Featuring Trippie Redd Thick Of It
Cody Johnson & Carrie Underwood I'm Gonna Love You
Megan Thee Stallion Featuring Yuki Chiba Mamushi
Thomas Rhett Beautiful As You
Tito Double P & Peso Pluma Dos Dias
mgk & Jelly Roll Lonely Road
Sabrina Carpenter Good Graces
BossMan Dlow Shake Dat Ass (Twerk Song)
Addison Rae Diet Pepsi
Post Malone Featuring Luke Combs Guy For That
Jelly Roll Liar
Rod Wave The Best
The Kid LAROI Nights Like This
Moneybagg Yo Featuring Morgan Wallen Whiskey Whiskey
Hanumankind X Kalmi Big Dawgs
Eminem Houdini
Chris Stapleton Think I'm In Love With You
Zach Top I Never Lie
Rod Wave Even Love
21 Savage & Summer Walker Prove It
Chappell Roan Red Wine Supernova
The Marias No One Noticed
Megan Moroney Am I Okay?
Rod Wave & Be Charlotte Lost In Love
Chris Brown Residuals
BigXthaPlug Change Me
GloRilla & Megan Thee Stallion How I Look
Tito Double P El Lokeron
GloRilla & T-Pain I Luv Her
Rod Wave Waited 2 Late
Rod Wave Mike
Rod Wave D.A.R.E.
Rod Wave Scared Love
Future Lil Demon
Jennie Mantra
BigXthaPlug Leave Me Alone
Rod Wave Karma
run:
node server.js
setup-db:
sqlite3 billboard.db -cmd '.mode csv' -cmd '.import --csv billboard.csv top100' --cmd '.import --csv billboard2.csv top100'
install:
npm install express sqlite3
const sqlite3 = require('sqlite3').verbose();
const express = require("express");
const app = express();
const router = express.Router();
app.use(express.json());
const port = 3000;
// Start server
app.listen(port, () => {
console.log("Server running on port %PORT%".replace("%PORT%",port))
});
// open the database
let db = new sqlite3.Database('./billboard.db', sqlite3.OPEN_READWRITE, (err) => {
if (err) {
console.error(err.message);
}
console.log('Connected to the billboard top 100 database.');
});
/* GET Request /week/:num */
app.get("/week/:num", (req, res) => {
// Access id via: req.params.id
const sql = `SELECT * FROM top100 where week = ${req.params.num};`;
db.all(sql, [], (err, row) => {
if (err) {
res.status(400).json({"error":err.message});
return console.error(err.message);
}
res.status(200).json({row});
})
});
// Default response for any other request
app.use(function(req, res){
res.status(404);
});
-- (a) adding record to the table
INSERT INTO top100 VALUES ('Michael Jackson', 'Thriller');
-- (b) get a specific song, i.e. by artist
-- * means return all attributes
SELECT * FROM top100 WHERE artist = 'Michael Jackson';
-- (c) get nth song
-- rowid is a attribute assigned by sqlite
SELECT * FROM top100 WHERE rowid = 6;
-- get number of songs per artist
select artist, count(*) as Count from top100 GROUP BY artist ORDER BY Count DESC;
-- (d) change name of artist or other text
-- update for updating data; ALTER for updating table structure
UPDATE top100 SET Artist = 'MULTIPLE' WHERE Artist like '% Featuring%';
-- to replace substring
UPDATE top100 SET Artist = replace(Artist, 'Featuring', 'feat.');
-- (e) delete records matching condition
DELETE FROM top100 WHERE artist = 'Michael Jackson';
-- (i) create table
CREATE TABLE anothertable (column1 TEXT, column2 TEXT);
-- (ii) counting records in a table
-- use aggregating function count(*) to count
SELECT count(*) FROM top100;
-- (iii) list everything in a table
SELECT * FROM top100;
-- (iv) change column names
ALTER TABLE top100 RENAME Song TO Title;
-- (v) add or remove columns
-- adding column
ALTER TABLE top100 ADD COLUMN week;
-- remove column with DROP keyword
-- update week column
UPDATE top100 SET week = 1 where rowid < 101;
UPDATE top100 SET week = 2 where rowid > 100;
-- setting to today's date UPDATE top100 SET week = date();
-- (vi) delete the table
DROP TABLE top100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment