| 18 | email = Column(String(100)) |
| 19 | |
| 20 | def main(): |
| 21 | # Create test database |
| 22 | db_path = tempfile.mktemp(suffix='.db') |
| 23 | |
| 24 | # Start pgsqlite with debug logging |
| 25 | env = os.environ.copy() |
| 26 | env['RUST_LOG'] = 'pgsqlite=debug' |
| 27 | |
| 28 | pgsqlite_proc = subprocess.Popen([ |
| 29 | '/home/eran/work/pgsqlite/target/release/pgsqlite', |
| 30 | '--database', db_path, |
| 31 | '--port', '15513', |
| 32 | ], env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 33 | |
| 34 | time.sleep(2) |
| 35 | |
| 36 | try: |
| 37 | # Create SQLAlchemy engine |
| 38 | engine = create_engine( |
| 39 | 'postgresql+psycopg://postgres@localhost:15513/main', |
| 40 | echo=True # Show SQL queries |
| 41 | ) |
| 42 | |
| 43 | print("🔧 Step 1: Testing basic connection...") |
| 44 | with engine.connect() as conn: |
| 45 | result = conn.execute(text("SELECT 1")).scalar() |
| 46 | print(f"✅ Basic connection works: {result}") |
| 47 | |
| 48 | print("\n🔧 Step 2: Testing table creation...") |
| 49 | Base.metadata.create_all(engine) |
| 50 | print("✅ Table creation successful") |
| 51 | |
| 52 | print("\n🔧 Step 3: Testing ORM session...") |
| 53 | Session = sessionmaker(bind=engine) |
| 54 | session = Session() |
| 55 | |
| 56 | # Test basic insert |
| 57 | try: |
| 58 | user = User(username='test_user', email='test@example.com') |
| 59 | session.add(user) |
| 60 | session.commit() |
| 61 | print("✅ Insert successful") |
| 62 | except Exception as e: |
| 63 | print(f"❌ Insert failed: {e}") |
| 64 | session.rollback() |
| 65 | return 1 |
| 66 | |
| 67 | # Test basic query |
| 68 | try: |
| 69 | users = session.query(User).all() |
| 70 | print(f"✅ Query successful: found {len(users)} users") |
| 71 | except Exception as e: |
| 72 | print(f"❌ Query failed: {e}") |
| 73 | return 1 |
| 74 | |
| 75 | # Test filtered query |
| 76 | try: |
| 77 | user = session.query(User).filter(User.username == 'test_user').first() |