Last active
August 29, 2015 14:03
-
-
Save jvanasco/2ff0b9a31ac45198a060 to your computer and use it in GitHub Desktop.
SqlAlchemy Example; https://groups.google.com/d/topic/sqlalchemy/PQ6rAqhEYMA/discussion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import * | |
from sqlalchemy.orm import * | |
from sqlalchemy.ext.declarative import declarative_base | |
import sqlalchemy.exc | |
import base64 | |
Base = declarative_base() | |
class Friends(Base): | |
__tablename__ = 'friends' | |
id = Column(Integer, primary_key=True) | |
name = Column(String(50)) | |
e = create_engine("sqlite://", echo=True) | |
Base.metadata.create_all(e) | |
s = Session(e) | |
def post_insert(username): | |
"""original function""" | |
conn = engine.connect() | |
puresql = sqla.text("INSERT INTO friends(name) VALUES(:encoded)") | |
conn.execute(puresql,encoded = encoded) | |
username = "12345678" | |
encoded = base64.b64encode(username.encode('utf-8')) | |
puresql = sqlalchemy.text("INSERT INTO friends(name) VALUES(:encoded)") | |
s.connection().execute( puresql, encoded = encoded ) | |
s.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment