-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
93 lines (79 loc) · 2.98 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from calendar import c
from sqlalchemy import update
from jinja2 import select_autoescape
from script import service
from script.db_service.members_service import MembersService
from script.model.members import Members
import sqlalchemy
from sqlalchemy import MetaData, create_engine
from sqlalchemy import Table
from sqlalchemy import insert, select
from sqlalchemy.orm import sessionmaker
import json
from script.db_service.member_private_calendar_service import MemberPrivateCalendarService
from script.db_service.member_calendar_event_service import MemberCalendarEventService
from script.service.dbService import DbService
def session_insert_test():
engine = create_engine(
"mysql+pymysql://root:root@localhost/live_now", echo=True)
Session = sessionmaker(engine)
# https://docs.sqlalchemy.org/en/20/orm/session.html
with Session() as session:
result = None
# member_obj = {
# 'member_mail': '[email protected]'
# }
member = Members(member_id=1, member_mail='[email protected]')
result = session.add(member)
session.commit()
print(result)
def insert_member():
# https://docs.sqlalchemy.org/en/20/core/dml.html#sqlalchemy.sql.expression.insert
engine = create_engine(
"mysql+pymysql://root:root@localhost/live_now", echo=True)
member_obj = {
'member_mail': '[email protected]'
}
metadata_obj = MetaData()
table = Table("members", metadata_obj, autoload_with=engine)
with engine.connect() as conn:
stmt = (
insert(table)
.values(member_obj)
)
result = conn.execute(stmt)
conn.commit()
id = result.inserted_primary_key
print(id)
def select_member():
engine = create_engine(
"mysql+pymysql://root:root@localhost/live_now", echo=True)
Session = sessionmaker(engine)
with Session() as session:
result = None
# member = Members(member_id=1, member_mail='[email protected]')
stmt = (select(Members).where(Members.member_id == 2))
result = session.execute(stmt)
for row in result:
print(row)
def update_member():
engine = create_engine(
"mysql+pymysql://root:root@localhost/live_now", echo=True)
Session = sessionmaker(engine)
metadata_obj = MetaData()
with Session() as session:
members_table = Table("members", metadata_obj, autoload_with=engine)
stmt = update(members_table).where(members_table.c.member_id == 6).values({
'member_mail': '[email protected]',
'member_line_user_id': 'jessie0320'
})
session.execute(stmt)
session.commit()
def create_private_calendar_test():
service = MemberPrivateCalendarService()
calendar = service.create_private_calendar('myCalendar', 7)
print(calendar)
if __name__ == "__main__":
service = DbService()
calendar_event = service.query_concert_time_table('2024-05-05', '2024-05-12')
print(calendar_event)