Skip to content

Instantly share code, notes, and snippets.

@parkerfoshay
Created November 22, 2022 17:58
Show Gist options
  • Save parkerfoshay/db13135e88d459e3ae9f3a33ffd67ae3 to your computer and use it in GitHub Desktop.
Save parkerfoshay/db13135e88d459e3ae9f3a33ffd67ae3 to your computer and use it in GitHub Desktop.
L1-mapping-to-mongodb
{
_id: ObjectId("5b9d9b9b9b9b9b9b9b9b9b9b"),
first_name: "John",
last_name: "Doe",
phone: "123-456-7890",
age: 25,
start_date: ISODate("2018-09-01T00:00:00.000Z"),
settings: {
theme: "dark",
switch_controls: true,
magnify: false
},
addresses: [
{street: "123 Main St", city: "New York", state: "NY"},
{street: "456 Broadway", city: "New York", state: "NY"}
],
favorites: [ "Peanut Butter", "Chocolate", "Vanilla" ]
}
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
phone TEXT,
age INT,
start_date TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS settings (
id SERIAL PRIMARY KEY,
dark_mode BOOLEAN DEFAULT FALSE NOT NULL,
switch_controls BOOLEAN DEFAULT FALSE NOT NULL,
magnify BOOLEAN DEFAULT FALSE NOT NULL,
user_id INT REFERENCES users(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS addresses (
id SERIAL PRIMARY KEY,
street TEXT NOT NULL,
city TEXT NOT NULL,
state TEXT NOT NULL,
user_id INTEGER REFERENCES user(id) ON DELETE CASCADE
);
CREATE TABLE favorites (
id SERIAL PRIMARY KEY,
name VARCHAR(30) NOT NULL,
user_id INTEGER NOT NULL REFERENCES user(id) ON DELETE CASCADE
);
INSERT INTO users (first_name, last_name, phone, age)
VALUES
('Nancy', 'Smith', "5234560987", 29),
('Douglas', 'Lowel', "5234768907", 23),
('Kai', 'Tran', "9198761234", 43),
('Linzey', 'Rivers', "7659023456", 54),
('Mira', 'Chan', "7650981234", 88);
INSERT INTO settings (dark_mode, switch_controls, magnify, user_id)
VALUES
(TRUE, FALSE, FALSE, 2),
(FALSE, TRUE, FALSE, 3),
(FALSE, FALSE, TRUE, 4),
(TRUE, TRUE, FALSE, 5),
(FALSE, FALSE, FALSE, 1);
INSERT INTO addresses (street, city, state, user_id)
VALUES
('123 Main St', 'New York', 'NY', 1),
('Roadrunner St', 'Phoenix', 'AZ', 2),
('Jefferson St', 'Cleveland', 'OH', 3),
('Beach St', 'Tampa', 'FL', 4),
('Lucky St', 'Las Vegas', 'NV', 5);
INSERT INTO favorites (name, user_id)
VALUES
('Peanut Butter', 1),
('Chocolate', 2),
('Vanilla', 3),
('Strawberry', 4),
('Mint', 5),
('Cookies and Cream', 1),
('Rocky Road', 2),
('Moose Tracks', 3),
('Chocolate Chip Cookie Dough', 4),
('Chocolate Fudge Brownie', 5),
('Chocolate Peanut Butter Cup', 1),
('Chocolate Chip', 2),
('Chocolate Almond', 3),
('Chocolate Mocha Almond Fudge', 4),
('Chocolate Caramel Cluster', 5),
('Chocolate Chip Cookie Dough', 1),
('Chocolate Peanut Butter Cup', 2),
('Chocolate Chip', 3),
('Chocolate Almond', 4),
('Chocolate Mocha Almond Fudge', 5),
('Chocolate Caramel Cluster', 1),
('Chocolate Chip Cookie Dough', 2),
('Chocolate Peanut Butter Cup', 3),
('Chocolate Chip', 4),
('Chocolate Almond', 5),
('Chocolate Mocha Almond Fudge', 1),
('Chocolate Caramel Cluster', 2),
('Chocolate Chip Cookie Dough', 3),
('Chocolate Peanut Butter Cup', 4),
('Chocolate Chip', 5),
('Chocolate Almond', 1),
('Chocolate Mocha Almond Fudge', 2),
('Chocolate Caramel Cluster', 3),
('Chocolate Chip Cookie Dough', 4),
('Chocolate Peanut Butter Cup', 5),
('Chocolate Chip', 1),
('Chocolate Almond', 2),
('Chocolate Mocha Almond Fudge', 3),
('Chocolate Caramel Cluster', 4),
('Chocolate Chip Cookie Dough', 5),
('Chocolate Peanut Butter Cup', 1),
('Chocolate Chip', 2),
('Chocolate Almond', 3),
('Chocolate Mocha Almond Fudge', 4),
('Chocolate Caramel Cluster', 5),
('Chocolate Chip Cookie Dough', 1),
('Chocolate Peanut Butter Cup', 2),
('Chocolate Chip', 3),
('Chocolate Almond', 4),
('Chocolate Mocha Almond Fudge', 5),
('Chocolate Caramel Cluster', 1),
('Chocolate Chip Cookie Dough', 2),
('Chocolate Peanut Butter Cup', 3),
('Chocolate Chip', 4),
('Chocolate Almond', 5),
('Chocolate Mocha Almond Fudge', 1),
('Chocolate Caramel Cluster', 2),
('Chocolate Chip Cookie Dough', 3),
('Chocolate Peanut Butter Cup', 4),
('Chocolate Chip', 5),
('Vanilla', 3),
('Strawberry', 4),
('Mint', 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment