22 lines
		
	
	
		
			544 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			544 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import sqlite3
 | 
						||
import os
 | 
						||
 | 
						||
DB_PATH = "messenger.db"
 | 
						||
 | 
						||
def get_connection():
 | 
						||
    return sqlite3.connect(DB_PATH)
 | 
						||
 | 
						||
def init_db():
 | 
						||
    if not os.path.exists(DB_PATH):
 | 
						||
        conn = get_connection()
 | 
						||
        cursor = conn.cursor()
 | 
						||
        cursor.execute('''
 | 
						||
            CREATE TABLE IF NOT EXISTS chats (
 | 
						||
                id INTEGER PRIMARY KEY AUTOINCREMENT,
 | 
						||
                title TEXT NOT NULL
 | 
						||
            )
 | 
						||
        ''')
 | 
						||
        cursor.execute('INSERT INTO chats (title) VALUES (?)', ("Чат с Alice",))
 | 
						||
        conn.commit()
 | 
						||
        conn.close()
 |