init proj
This commit is contained in:
commit
282bd73d42
|
@ -0,0 +1,37 @@
|
||||||
|
#%%
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
"""
|
||||||
|
#SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db" # SQLite
|
||||||
|
engine = create_engine(
|
||||||
|
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} # Opcja dla SQLite
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
|
#%%
|
||||||
|
SQLALCHEMY_DATABASE_URL = "mysql+mysqlconnector://root:secret@172.18.0.3:3306/mpabi" # Przykład dla MySQL
|
||||||
|
engine = create_engine(
|
||||||
|
SQLALCHEMY_DATABASE_URL,
|
||||||
|
)
|
||||||
|
|
||||||
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
|
#%%
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
with engine.connect() as conn:
|
||||||
|
result = conn.execute(text("select 'hello world'"))
|
||||||
|
print(result.all())
|
||||||
|
|
||||||
|
#%%
|
||||||
|
with engine.connect() as conn:
|
||||||
|
conn.execute(text("CREATE TABLE some_table (x int, y int)"))
|
||||||
|
conn.execute(
|
||||||
|
text("INSERT INTO some_table (x, y) VALUES (:x, :y)"),
|
||||||
|
[{"x": 1, "y": 1}, {"x": 2, "y": 4}],
|
||||||
|
)
|
||||||
|
conn.commit()
|
Loading…
Reference in New Issue