예제 #1
0
파일: request.py 프로젝트: ranjithtenz/chai
    def connect_db(self):
        """
		Selects db
		"""
        if self.cookies.get("db"):
            config.db_name = self.cookies["db"]

        from sqlachemy import create_engine, sessionmaker

        chai.db_engine = create_engine("mysql://%(db_user)s:%(db_password)s@localhost/%(db_name)s", config.__dict__)
        chai.db_session = sessionmaker(bind=chai.db_engine)()
예제 #2
0
    def connect_db(self):
        """
		Selects db
		"""
        if self.cookies.get('db'):
            config.db_name = self.cookies['db']

        from sqlachemy import create_engine, sessionmaker

        chai.db_engine = create_engine(
            'mysql://%(db_user)s:%(db_password)s@localhost/%(db_name)s',
            config.__dict__)
        chai.db_session = sessionmaker(bind=chai.db_engine)()
예제 #3
0
    def __init__(self):
        """constructor for DB"""

        self.__engine = db.create_engine("mysql+mysqldb://{}:{}@{}/{}".format(
            getenv("HBNB_MYSQL_USER"),
            detenv("HBNB_MYSQL_PWD"),
            getenv("HBNB_MYSQL_HOST"),
            getenv("HBNB_MYSQL_DB"),
            pool_pre_ping=True))
        Session = sessionmaker(bind=self.__engine)
        self._session = Session()

        if getenv("HBNB_ENV") == 'test':
            Base.metadata.drop_all(self.__engine)
예제 #4
0
class Top10WeeklyRecord(Base):
    __tablename__ = 'Top10WeeklyRecord'
    DATE = Column(Date, primary_key=True)
    NAME = Column(String, primary_key=True)
    SYMBOL = Column(String)
    MARKET_CAP_USD = Column(Float)
    PERCENT_CHANGE_1H = Column(Float)
    PERCENT_CHANGE_24H = Column(Float)
    PERCENT_CHANGE_7D = Column(Float)
    PRICE_USD = Column(Float)
    INDEX_PORTION = Column(Float)


engine = create_engine(
    'postgresql://*****:*****@devdbinstance.cueh4niuygr6.us-west-2.rds.amazonaws.com:5432/thanos'
)
metadata = MetaData()
Session = sessionmaker(bind=engine)

conversion_list = ['market_cap_usd', 'price_usd']

coinmarketcap = Market()
#top_10
top_10 = coinmarketcap.ticker(start=0, limit=10, sort='Rank')
df_top10 = pd.DataFrame(top_10)
df_top10[conversion_list] = df_top10[conversion_list].apply(pd.to_numeric)
total_top10_marketcap = df_top10['market_cap_usd'].sum()
df_top10 = df_top10[[
    'name', 'symbol', 'market_cap_usd', 'percent_change_1h',
    'percent_change_24h', 'percent_change_7d', 'price_usd'
예제 #5
0
from sqlachemy import (create_engine, MetaData, Column,
                            Table, Integar,
                            String, DataTime
from datetime import datetime



engine = create_engine('sqlite:///banco.db', echo=True)
metadata = MetaData(bind=engine)

user_table = Table('usuarios',
                    metadata,
                        Column('id',Integer, primary_key=True),
                        Column('nome', String(40), index=True),
                        Column('idade', Integer, nullable=False),
                        Column('senha', String),
                        Column('criado em', DateTime, default=datetime.now),
                        Column('atualizado_em', DateTime, onupdate=datetime.now)
                        
                        )

metadata.create_all(engine)

예제 #6
0
#coding:utf-8

from sqlachemy import Colmumn, String, create_engine
from sqlachemy.orm import sessionmark
from sqlachemy.ext.declarative import declarative_base

Base = declarative_base()
class User(Base):
    __tablename__ "user"
    id = Column(String(20), primary_key=True)
    name = Column(String(20))
engine = create_engine("mysql+mysqlconnector://root:12345@localhost:3306/test")
DBSession = sessionmaker(bind=engine)


    @property
    def id_pengembalian(self):
        return self.id_pengembalian
    @id_pengembalian.setter
    def id_pengembalian(self, id_pengembalian):
        self.id_pengembalian = id_pengembalian

    @property
    def denda(self):
        return self.denda
    @denda.setter
    def denda(self, denda):
        self.denda = denda

class tb_transaksi(Base):
    __tablename__ = "tb_transaksi"

    id_pinjam = Column('id_pinjam', Integer, primary_key=True)
    id_anggota = Column('id_anggota', Integer, Unique=True)
    id_petugas = Column('id_petugas', Integer, Unique=True)
    id_buku = Column('id_buku', Integer, Unique=True)
    tgl_pinjam = Column('tgl_pinjam', Date)
    tgl_kembali = Column('tgl_kembali', Date)
    status = Column('status', Boolean)
    denda = Column('denda', Integer)

engine = create_engine('sqllite:///:memory:', echo=True)
Base.metadata.create_all(bind=engine)
Session = sessionmaker(bind=engine)
예제 #8
0
import os
from sqlachemy import create_engine
from sqlachemy.orm import scoped_session, sessionmaker

engine = create_engine (os.getenv("DATABASE_URL"))
db = scoped_session (sessionmaker(bind=engine))
// creating different session for different people//

def main():
flights = db.execute("SELECT origin, destination, duraation FROM flights").feetchall() //run the command and get me all the query and give me a list of all of the individual result//
for flights in flight:
print (f"{flight.origin} to {flight.destination}, {flight.destination} minutes.")

if__name__ = __main__
main()


imoort csv
import os
from sqlachemy import create_engine
from sqlachemy.orm import scoped_session, sessionmaker


engine = create_engine (os.getenv("DATABASE_URL"))
db = scoped_session (sessionmaker(bind=engine))
// creating different session for different people//

def main (): 
f = open ("flights.csv")
reader = csv.reader (f) // i want to read file f as a csv file//
for origin, destination, duration in reader: 
예제 #9
0
    'port': 3306,
    'user': '******',
    'password': '******',
    'database': 'classicmodels',
}

db_user = config.get('user')
db_pwd = config.get('password')
db_host = config.get('host')
db_port = config.get('port')
db_name = config.get('database')

connection_str = f'mysql+pymysql://{db_user}:{db_pwd}@{db_host}:{db_port}/{db_name}

#connect to database
engine = create_engine(connection_str)
connection = engine.connect()
print(' --- MySQL Docker Container Python connection ok --- \n')







DB_URL = 'mysql+mysqldb://root:root@localhost:3306/employee'
ENGINE = create_engine(DB_URL)

metadata = MetaData()

user = Table ('user', metadata,