Пример #1
0
def get_user(user_id):
    finded_user = None
    with connection.cursor() as cursor:
        sql = 'select * from users where users.id=%s'
        cursor.execute(sql, user_id)
        finded_user = cursor.fetchone()
    return finded_user
Пример #2
0
def check_user_username(username):
    finded_user = None
    with connection.cursor() as cursor:
        sql = 'select * from users where users.username=%s'
        cursor.execute(sql, username)
        finded_user = cursor.fetchone()
    return finded_user
Пример #3
0
def check_user_email(email):
    finded_user = None
    with connection.cursor() as cursor:
        sql = 'select * from users where users.email=%s'
        cursor.execute(sql, email)
        finded_user = cursor.fetchone()
    return finded_user
def blog_search(x):
    with connection.cursor() as cursor:
        # Create a new record
        sql = """SELECT * from blog_project.blogs1 WHERE title LIKE %s"""
        cursor.execute(sql, ("%" + x + "%"))
    connection.commit()
    return cursor.fetchall()
def blog_delete(id):
    with connection.cursor() as cursor:
        # Create a new record
        sql = """delete from blog_project.blogs1 where id=%s"""
        cursor.execute(sql, id)
    connection.commit()
    return cursor.fetchone()
def website_table():
    with connection.cursor() as cursor:
        # Create a new record
        sql = """SELECT * From blog_project.about_website
            """
        cursor.execute(sql)
    return cursor.fetchone()
def get_user_count():
    with connection.cursor() as cursor:
        # Create a new record
        sql = """select count(id) from blog_project.users 
        """
        cursor.execute(sql)
    return cursor.fetchone()['count(id)']
def get_blog_user_details(blog_id):
    with connection.cursor() as cursor:
        # Create a new record
        sql = """select users.first_name,users.surname from blog_project.blogs1
        INNER JOIN blog_project.users on users.id = blogs1.user_id where blogs1.id = %s
        """
        cursor.execute(sql, blog_id)
    return cursor.fetchone()
def blog_update(title, description, owner_name, id, **kwargs):
    with connection.cursor() as cursor:
        # Create a new record
        sql = "Update blog_project.blogs1 Set title=%s, description=%s, owner_name=%s where id =%s"
        now = datetime.now()
        created_ad = now.strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(sql, (title, description, owner_name, id))
    connection.commit()
def create_website_table():
    with connection.cursor() as cursor:
        # Create a new record
        sql = """insert into blog_project.about_website(social_adress, email,phone_number)
            values('Blog.com', 'Blog@gmail','+994000000') 
            """
        cursor.execute(sql)
    connection.commit()
def all_blogs(limit_f_index=None, limit_s_index=None):
    limit_query = ''
    if limit_f_index is not None and limit_s_index is not None:
        limit_query = f'LIMIT {limit_f_index}, {limit_s_index}'
    with connection.cursor() as cursor:
        # Create a new record
        sql = f"""select * from blog_project.blogs1 {limit_query};"""
        cursor.execute(sql)
    return cursor.fetchall()
Пример #12
0
def create_users_table():
    with connection.cursor() as cursor:
        # Create a new record
        sql = """create table if not exists users(
            id int(11) unsigned AUTO_INCREMENT PRIMARY KEY,
            username varchar(50) NOT NULL UNIQUE,
            email varchar(40) NOT NULL UNIQUE,
            first_name varchar(40) NOT NULL,
            surname varchar(40) NOT NULL,
            password varchar(255) NOT NULL,
            date_joined datetime NOT NULL,
            is_active tinyint(1) default 0
            );
            """
        cursor.execute(sql)
    connection.commit()
def create_blog_table():
    with connection.cursor() as cursor:
        # Create a new record
        sql = """create table if not exists blogs1(
            id int(11) unsigned AUTO_INCREMENT PRIMARY KEY,
            title varchar(255) NOT NULL,
            description text NOT NULL,
            user_id int(11) unsigned NOT NULL,
            image varchar(500),
            created_at datetime NOT NULL,
            is_published tinyint(1) default 1,
            FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE,
            INDEX (id, user_id)
            ); 
            """
        cursor.execute(sql)
    connection.commit()
def create_blog(title,
                description,
                user_id,
                image,
                is_published=True,
                **kwargs):
    with connection.cursor() as cursor:
        # Create a new record
        sql = """insert into blog_project.blogs1(title, description, user_id, image, created_at, is_published)
            values(%s, %s, %s, %s, %s, %s) 
            """
        now = datetime.now()
        created_ad = now.strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(
            sql,
            (title, description, user_id, image, created_ad, is_published))
    connection.commit()
Пример #15
0
def create_user(username,
                email,
                first_name,
                surname,
                password,
                is_active=1,
                **kwargs):
    hashed_pass = generate_password_hash(password)
    with connection.cursor() as cursor:
        # Create a new record
        sql = """INSERT INTO users(username, email, first_name, surname, password, date_joined, is_active)
            VALUES(%s, %s, %s, %s, %s, %s, %s);
        """
        now = datetime.now()
        date_joined = now.strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(sql, (username, email, first_name, surname, hashed_pass,
                             date_joined, is_active))
    connection.commit()
def blog_detail(id):
    with connection.cursor() as cursor:
        # Create a new record
        sql = """select * from blog_project.blogs1 where id=%s"""
        cursor.execute(sql, id)
    return cursor.fetchone()