Diff
checker
Text
Text
Images
Documents
Excel
Folders
Legal
Enterprise
Desktop
Pricing
Sign in
Download Diffchecker Desktop
Compare text
Find the difference between two text files
Tools
History
Real-time editor
Hide unchanged lines
Disable line wrap
Layout
Split
Unified
Diff precision
Smart
Word
Char
Syntax highlighting
Choose syntax
Ignore
Transform text
Go to first change
Edit input
Diffchecker Desktop
The most secure way to run Diffchecker. Get the Diffchecker Desktop app: your diffs never leave your computer!
Get Desktop
Movie watchlist database.py diff between SQLite and PostgreSQL
Created
6 years ago
Diff never expires
Clear
Export
Share
Explain
21 removals
Lines
Total
Removed
Characters
Total
Removed
To continue using this feature, upgrade to
Diff
checker
Pro
View Pricing
81 lines
Copy
47 additions
Lines
Total
Added
Characters
Total
Added
To continue using this feature, upgrade to
Diff
checker
Pro
View Pricing
91 lines
Copy
Copy
Copied
Copy
Copied
import os
import datetime
import datetime
Copy
Copied
Copy
Copied
import
sqlite3
import
psycopg2
from dotenv import load_dotenv
load_dotenv()
CREATE_MOVIES_TABLE = """CREATE TABLE IF NOT EXISTS movies (
CREATE_MOVIES_TABLE = """CREATE TABLE IF NOT EXISTS movies (
Copy
Copied
Copy
Copied
id
INTEGER
PRIMARY KEY,
id
SERIAL
PRIMARY KEY,
name TEXT,
name TEXT,
release_timestamp REAL
release_timestamp REAL
);"""
);"""
CREATE_USERS_TABLE = """CREATE TABLE IF NOT EXISTS users (
CREATE_USERS_TABLE = """CREATE TABLE IF NOT EXISTS users (
username TEXT PRIMARY KEY
username TEXT PRIMARY KEY
);"""
);"""
CREATE_WATCHED_TABLE = """CREATE TABLE IF NOT EXISTS watched (
CREATE_WATCHED_TABLE = """CREATE TABLE IF NOT EXISTS watched (
user_username TEXT,
user_username TEXT,
movie_id INTEGER,
movie_id INTEGER,
FOREIGN KEY(user_username) REFERENCES users(username),
FOREIGN KEY(user_username) REFERENCES users(username),
FOREIGN KEY(movie_id) REFERENCES movies(id)
FOREIGN KEY(movie_id) REFERENCES movies(id)
);"""
);"""
Copy
Copied
Copy
Copied
INSERT_MOVIE = "INSERT INTO movies (name, release_timestamp) VALUES (
?, ?
)"
INSERT_MOVIE = "INSERT INTO movies (name, release_timestamp) VALUES (
%s, %s
)"
SELECT_ALL_MOVIES = "SELECT * FROM movies;"
SELECT_ALL_MOVIES = "SELECT * FROM movies;"
Copy
Copied
Copy
Copied
SELECT_UPCOMING_MOVIES = "SELECT * FROM movies WHERE release_timestamp >
?
;"
SELECT_UPCOMING_MOVIES = "SELECT * FROM movies WHERE release_timestamp >
%s
;"
INSERT_USER = "INSERT INTO users (username) VALUES (
?
)"
INSERT_USER = "INSERT INTO users (username) VALUES (
%s
)"
INSERT_WATCHED_MOVIE = "INSERT INTO watched (user_username, movie_id) VALUES (
?, ?
)"
INSERT_WATCHED_MOVIE = "INSERT INTO watched (user_username, movie_id) VALUES (
%s, %s
)"
SELECT_WATCHED_MOVIES = """SELECT movies.*
SELECT_WATCHED_MOVIES = """SELECT movies.*
FROM users
FROM users
JOIN watched ON users.username = watched.user_username
JOIN watched ON users.username = watched.user_username
JOIN movies ON watched.movie_id = movies.id
JOIN movies ON watched.movie_id = movies.id
Copy
Copied
Copy
Copied
WHERE users.username =
?
;"""
WHERE users.username =
%s
;"""
SEARCH_MOVIE = """SELECT * FROM movies WHERE name LIKE
?
;"""
SEARCH_MOVIE = """SELECT * FROM movies WHERE name LIKE
%s
;"""
Copy
Copied
Copy
Copied
connection =
sqlite3
.connect(
"data.db")
# Remember to not store the database URI in your code!
connection =
psycopg2
.connect(
os.environ.get("DATABASE_URI"))
def create_tables():
def create_tables():
with connection:
with connection:
Copy
Copied
Copy
Copied
connection.
execute(CREATE_MOVIES_TABLE)
with
connection.
cursor() as cursor:
connection
.execute(CREATE_USERS_TABLE)
cursor.
execute(CREATE_MOVIES_TABLE)
connection
.execute(CREATE_WATCHED_TABLE)
cursor
.execute(CREATE_USERS_TABLE)
cursor
.execute(CREATE_WATCHED_TABLE)
def add_movie(name, release_timestamp):
def add_movie(name, release_timestamp):
with connection:
with connection:
Copy
Copied
Copy
Copied
connection.
execute(INSERT_MOVIE, (name, release_timestamp))
with
connection.
cursor() as cursor:
cursor.
execute(INSERT_MOVIE, (name, release_timestamp))
def get_movies(upcoming=False):
def get_movies(upcoming=False):
with connection:
with connection:
Copy
Copied
Copy
Copied
cursor =
connection.cursor()
with
connection.cursor()
as cursor:
if upcoming:
if upcoming:
today_timestamp = datetime.datetime.today().timestamp()
today_timestamp = datetime.datetime.today().timestamp()
cursor.execute(SELECT_UPCOMING_MOVIES, (today_timestamp,))
cursor.execute(SELECT_UPCOMING_MOVIES, (today_timestamp,))
else:
else:
cursor.execute(SELECT_ALL_MOVIES)
cursor.execute(SELECT_ALL_MOVIES)
return cursor.fetchall()
return cursor.fetchall()
def add_user(username):
def add_user(username):
with connection:
with connection:
Copy
Copied
Copy
Copied
connection.
execute(INSERT_USER, (username,))
with
connection.
cursor() as cursor:
cursor.
execute(INSERT_USER, (username,))
def watch_movie(username, movie_id):
def watch_movie(username, movie_id):
with connection:
with connection:
Copy
Copied
Copy
Copied
connection.
execute(INSERT_WATCHED_MOVIE, (username, movie_id))
with
connection.
cursor() as cursor:
cursor.
execute(INSERT_WATCHED_MOVIE, (username, movie_id))
def get_watched_movies(username):
def get_watched_movies(username):
with connection:
with connection:
Copy
Copied
Copy
Copied
cursor =
connection.cursor()
with
connection.cursor()
as cursor:
cursor.execute(SELECT_WATCHED_MOVIES, (username,))
cursor.execute(SELECT_WATCHED_MOVIES, (username,))
return cursor.fetchall()
return cursor.fetchall()
def search_movies(search_term):
def search_movies(search_term):
with connection:
with connection:
Copy
Copied
Copy
Copied
cursor =
connection.cursor()
with
connection.cursor()
as cursor:
cursor.execute(SEARCH_MOVIE, (f"%{search_term}%",))
cursor.execute(SEARCH_MOVIE, (f"%{search_term}%",))
return cursor.fetchall()
return cursor.fetchall()
Saved diffs
Original text
Open file
import datetime import sqlite3 CREATE_MOVIES_TABLE = """CREATE TABLE IF NOT EXISTS movies ( id INTEGER PRIMARY KEY, name TEXT, release_timestamp REAL );""" CREATE_USERS_TABLE = """CREATE TABLE IF NOT EXISTS users ( username TEXT PRIMARY KEY );""" CREATE_WATCHED_TABLE = """CREATE TABLE IF NOT EXISTS watched ( user_username TEXT, movie_id INTEGER, FOREIGN KEY(user_username) REFERENCES users(username), FOREIGN KEY(movie_id) REFERENCES movies(id) );""" INSERT_MOVIE = "INSERT INTO movies (name, release_timestamp) VALUES (?, ?)" SELECT_ALL_MOVIES = "SELECT * FROM movies;" SELECT_UPCOMING_MOVIES = "SELECT * FROM movies WHERE release_timestamp > ?;" INSERT_USER = "INSERT INTO users (username) VALUES (?)" INSERT_WATCHED_MOVIE = "INSERT INTO watched (user_username, movie_id) VALUES (?, ?)" SELECT_WATCHED_MOVIES = """SELECT movies.* FROM users JOIN watched ON users.username = watched.user_username JOIN movies ON watched.movie_id = movies.id WHERE users.username = ?;""" SEARCH_MOVIE = """SELECT * FROM movies WHERE name LIKE ?;""" connection = sqlite3.connect("data.db") def create_tables(): with connection: connection.execute(CREATE_MOVIES_TABLE) connection.execute(CREATE_USERS_TABLE) connection.execute(CREATE_WATCHED_TABLE) def add_movie(name, release_timestamp): with connection: connection.execute(INSERT_MOVIE, (name, release_timestamp)) def get_movies(upcoming=False): with connection: cursor = connection.cursor() if upcoming: today_timestamp = datetime.datetime.today().timestamp() cursor.execute(SELECT_UPCOMING_MOVIES, (today_timestamp,)) else: cursor.execute(SELECT_ALL_MOVIES) return cursor.fetchall() def add_user(username): with connection: connection.execute(INSERT_USER, (username,)) def watch_movie(username, movie_id): with connection: connection.execute(INSERT_WATCHED_MOVIE, (username, movie_id)) def get_watched_movies(username): with connection: cursor = connection.cursor() cursor.execute(SELECT_WATCHED_MOVIES, (username,)) return cursor.fetchall() def search_movies(search_term): with connection: cursor = connection.cursor() cursor.execute(SEARCH_MOVIE, (f"%{search_term}%",)) return cursor.fetchall()
Changed text
Open file
import os import datetime import psycopg2 from dotenv import load_dotenv load_dotenv() CREATE_MOVIES_TABLE = """CREATE TABLE IF NOT EXISTS movies ( id SERIAL PRIMARY KEY, name TEXT, release_timestamp REAL );""" CREATE_USERS_TABLE = """CREATE TABLE IF NOT EXISTS users ( username TEXT PRIMARY KEY );""" CREATE_WATCHED_TABLE = """CREATE TABLE IF NOT EXISTS watched ( user_username TEXT, movie_id INTEGER, FOREIGN KEY(user_username) REFERENCES users(username), FOREIGN KEY(movie_id) REFERENCES movies(id) );""" INSERT_MOVIE = "INSERT INTO movies (name, release_timestamp) VALUES (%s, %s)" SELECT_ALL_MOVIES = "SELECT * FROM movies;" SELECT_UPCOMING_MOVIES = "SELECT * FROM movies WHERE release_timestamp > %s;" INSERT_USER = "INSERT INTO users (username) VALUES (%s)" INSERT_WATCHED_MOVIE = "INSERT INTO watched (user_username, movie_id) VALUES (%s, %s)" SELECT_WATCHED_MOVIES = """SELECT movies.* FROM users JOIN watched ON users.username = watched.user_username JOIN movies ON watched.movie_id = movies.id WHERE users.username = %s;""" SEARCH_MOVIE = """SELECT * FROM movies WHERE name LIKE %s;""" # Remember to not store the database URI in your code! connection = psycopg2.connect(os.environ.get("DATABASE_URI")) def create_tables(): with connection: with connection.cursor() as cursor: cursor.execute(CREATE_MOVIES_TABLE) cursor.execute(CREATE_USERS_TABLE) cursor.execute(CREATE_WATCHED_TABLE) def add_movie(name, release_timestamp): with connection: with connection.cursor() as cursor: cursor.execute(INSERT_MOVIE, (name, release_timestamp)) def get_movies(upcoming=False): with connection: with connection.cursor() as cursor: if upcoming: today_timestamp = datetime.datetime.today().timestamp() cursor.execute(SELECT_UPCOMING_MOVIES, (today_timestamp,)) else: cursor.execute(SELECT_ALL_MOVIES) return cursor.fetchall() def add_user(username): with connection: with connection.cursor() as cursor: cursor.execute(INSERT_USER, (username,)) def watch_movie(username, movie_id): with connection: with connection.cursor() as cursor: cursor.execute(INSERT_WATCHED_MOVIE, (username, movie_id)) def get_watched_movies(username): with connection: with connection.cursor() as cursor: cursor.execute(SELECT_WATCHED_MOVIES, (username,)) return cursor.fetchall() def search_movies(search_term): with connection: with connection.cursor() as cursor: cursor.execute(SEARCH_MOVIE, (f"%{search_term}%",)) return cursor.fetchall()
Find difference