<commit_before># -*- coding: utf-8 -*-
from flask import Flask
from contextlib import closing
import os, psycopg2

DB_SCHEMA= """
DROP TABLE IF EXISTS entries;
CREATE TABLE entries (
    id serial PRIMARY KEY,
    title VARCHAR (127) NOT NULL,
    text TEXT NOT NULL,
    created TIMESTAMP NOT NULL
    )
"""

app= Flask(__name__)
app.config['DATABASE']= os.environ.get(
    'DATABASE_URL', 'dbname=learning_journal user=store'
)

def connect_db():
    """Return a connection to the configured database"""
    return psycopg2.connect(app.config['DATABASE'])

def init_db():
    """Initialize the database using DB_SCHEMA

    WARNING: executing this function will drop existing tables.
    """
    with closing(connect_db()) as db:
        db.cursor().execute(DB_SCHEMA)
        db.commit()

@app.route('/')
def hello():
    return u'Hello World!'<commit_msg>Add functionality to establish connection with database, and disallow operation on said database if there is a problem with the connection<commit_after># -*- coding: utf-8 -*-
from flask import Flask
from flask import g
from contextlib import closing
import os, psycopg2

DB_SCHEMA= """
DROP TABLE IF EXISTS entries;
CREATE TABLE entries (
    id serial PRIMARY KEY,
    title VARCHAR (127) NOT NULL,
    text TEXT NOT NULL,
    created TIMESTAMP NOT NULL
    )
"""

app= Flask(__name__)
app.config['DATABASE']= os.environ.get(
    'DATABASE_URL', 'dbname=learning_journal user=store'
)

def connect_db():
    """Return a connection to the configured database"""
    return psycopg2.connect(app.config['DATABASE'])

def init_db():
    """Initialize the database using DB_SCHEMA

    WARNING: executing this function will drop existing tables.
    """
    with closing(connect_db()) as db:
        db.cursor().execute(DB_SCHEMA)
        db.commit()

def get_database_connection():
    db= getattr(g, 'db', None)
    if g.db is None:
        g.db= db= connect_db()
    return db

@app.teardown_request
def teardown_request(exception):
    db= getattr(g, 'db', None)
    if db is not None:
        if exception and isinstance(exception, psycopg2.Error):
            # if there was a problem with the database, rollback any
            # existing transaction
            db.rollback()
        else:
            db.commit()
        db.close()
    

@app.route('/')
def hello():
    return u'Hello World!'
{'fraction_non_alphanumeric': 0.10814249363867684, 'fraction_numerical': 0.00551314673452078, 'mean_word_length': 3.2658227848101267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4455249', 'n_tokens_mistral': 732, 'n_tokens_neox': 714, 'n_words': 241}