Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for cockroachdb #139

Open
dbist opened this issue May 19, 2020 · 0 comments
Open

add support for cockroachdb #139

dbist opened this issue May 19, 2020 · 0 comments

Comments

@dbist
Copy link

dbist commented May 19, 2020

With connection string cockroachdb://maxroach:maxroach@roach-0:26257/movr?sslcert=/certs/client.maxroach.crt&sslkey=/certs/client.maxroach.key&sslmode=verify-full&sslrootcert=/certs/ca.crt&port=26257

I get the following error

Can't load plugin: sqlalchemy.dialects:cockroachdb

The following code works in Jupyter once sqlalchemy-cockroachdb is installed.

# handling transaction error that we talk about in the blog and requiring to reconnect
# https://docs.sqlalchemy.org/en/13/orm/tutorial.html
# the entire sqlalchemy tutorial
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from cockroachdb.sqlalchemy import run_transaction
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String

import getpass
password = getpass.getpass()
sql_engine = create_engine('cockroachdb://maxroach:'+password+'@roach-0:26257/movr?sslcert=/certs/client.maxroach.crt&sslkey=/certs/client.maxroach.key&sslmode=verify-full&sslrootcert=/certs/ca.crt&port=26257')

Base = declarative_base()

class Vehicles(Base):
    __tablename__ = 'vehicles'
    city = Column(String, primary_key=True)
    type = Column(String)

session = sessionmaker(bind=sql_engine)
def run_select(session):
    for row in session.query(Vehicles.city, Vehicles.type).all():
        print(row.city, row.type)

run_transaction(session, run_select)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant