<commit_before>from psycopg2.extensions import AsIs
from strict_rfc3339 import timestamp_to_rfc3339_utcoffset

from skygear.container import SkygearContainer
from skygear.options import options as skyoptions
from skygear.utils import db
from skygear.utils.context import current_context, current_user_id


def _get_container():
    return SkygearContainer(api_key=skyoptions.masterkey,
                            user_id=current_user_id())


def _get_schema_name():
    return "app_%s" % skyoptions.appname


def _get_channel_by_user_id(user_id):
    #TODO: use database.query instead of raw SQL
    with db.conn() as conn:
        cur = conn.execute('''
            SELECT name
            FROM %(schema_name)s.user_channel
            WHERE _owner_id = %(user_id)s
            LIMIT 1;
            ''', {
            'schema_name': AsIs(_get_schema_name()),
            'user_id': user_id
        }
        )

        results = []
        for row in cur:
            results.append(row[0])

        if len(results) > 0:
            return results[0]


def _check_if_table_exists(tablename):<commit_msg>lama fix<commit_after>from psycopg2.extensions import AsIs
from strict_rfc3339 import timestamp_to_rfc3339_utcoffset

from skygear.container import SkygearContainer
from skygear.options import options as skyoptions
from skygear.utils import db
from skygear.utils.context import current_context, current_user_id


def _get_container():
    return SkygearContainer(api_key=skyoptions.masterkey,
                            user_id=current_user_id())


def _get_schema_name():
    return "app_%s" % skyoptions.appname


def _get_channel_by_user_id(user_id):
    # TODO: use database.query instead of raw SQL
    with db.conn() as conn:
        cur = conn.execute('''
            SELECT name
            FROM %(schema_name)s.user_channel
            WHERE _owner_id = %(user_id)s
            LIMIT 1;
            ''', {
            'schema_name': AsIs(_get_schema_name()),
            'user_id': user_id
        }
        )

        results = []
        for row in cur:
            results.append(row[0])

        if len(results) > 0:
            return results[0]


def _check_if_table_exists(tablename):
{'fraction_non_alphanumeric': 0.0815956482320943, 'fraction_numerical': 0.011786038077969175, 'mean_word_length': 2.5312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '450465', 'n_tokens_mistral': 704, 'n_tokens_neox': 681, 'n_words': 156}