Diff
checker
Texte
Texte
Images
Documents
Excel
Dossiers
Legal
Enterprise
Application de bureau
Prix
Se connecter
Télécharger Diffchecker Desktop
Comparer le texte
Trouver la différence entre deux fichiers texte
Outils
Historique
Éditeur live
Cacher identiques
Sans retour à la ligne
Vue
Divisé
Unifié
Niveau de précision
Intelligent
Mot
Caractère
Coloration syntaxique
Choisir la syntaxe
Ignorer
Transformer le texte
Aller au premier écart
Modifier l'entrée
Diffchecker Desktop
La façon la plus sécurisée d'utiliser Diffchecker. Obtenez l'application Diffchecker Desktop : vos diffs ne quittent jamais votre ordinateur !
Obtenir Desktop
Movie watchlist database.py diff between SQLite and PostgreSQL
Créé
il y a 6 ans
Le diff n'expire jamais
Effacer
Exporter
Partager
Expliquer
21 suppressions
Lignes
Total
Supprimé
Caractères
Total
Supprimé
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
81 lignes
Copier tout
47 ajouts
Lignes
Total
Ajouté
Caractères
Total
Ajouté
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
91 lignes
Copier tout
Copier
Copié
Copier
Copié
import os
import datetime
import datetime
Copier
Copié
Copier
Copié
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 (
Copier
Copié
Copier
Copié
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)
);"""
);"""
Copier
Copié
Copier
Copié
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;"
Copier
Copié
Copier
Copié
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
Copier
Copié
Copier
Copié
WHERE users.username =
?
;"""
WHERE users.username =
%s
;"""
SEARCH_MOVIE = """SELECT * FROM movies WHERE name LIKE
?
;"""
SEARCH_MOVIE = """SELECT * FROM movies WHERE name LIKE
%s
;"""
Copier
Copié
Copier
Copié
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:
Copier
Copié
Copier
Copié
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:
Copier
Copié
Copier
Copié
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:
Copier
Copié
Copier
Copié
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:
Copier
Copié
Copier
Copié
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:
Copier
Copié
Copier
Copié
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:
Copier
Copié
Copier
Copié
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:
Copier
Copié
Copier
Copié
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()
Différences enregistrées
Texte d'origine
Ouvrir un fichier
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()
Texte modifié
Ouvrir un fichier
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()
Trouver la différence