Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Last active June 14, 2018 14:53
Show Gist options
  • Save peteristhegreat/acfeebb140073c7655a35a7b098ea05e to your computer and use it in GitHub Desktop.
Save peteristhegreat/acfeebb140073c7655a35a7b098ea05e to your computer and use it in GitHub Desktop.
cx_Oracle, SqlAlchemy, Flask, specify schema Model
os.environ['TNS_ADMIN'] = os.path.join( 'oracle_tools', 'network', 'admin')
oracle_connection_string = 'oracle+cx_oracle://{username}:{password}@{tnsname}'.format(
username='user',
password='pass',
tnsname='TNS_SPACE',
)
oracle_schema = 'user_schema_1'
foreign_key_prefix = oracle_schema + '.'
app.config['SQLALCHEMY_DATABASE_URI'] = oracle_connection_string
oracle_db_metadata = schema.MetaData(schema=oracle_schema)
db = SQLAlchemy(app, metadata=oracle_db_metadata)
user_groups_table = db.Table(db_table_prefix + 'user_groups', db.Model.metadata,
db.Column('...', db.Integer, db.ForeignKey()),
db.Column('...', db.Integer, db.ForeignKey(foreign_key_prefix + 'group.id')),
# schema=oracle_schema # Not necessary because of the use of Metadata above
)
class User(db.Model):
__tablename__ = 'user'
# __table_args__ = {'schema': oracle_schema } # Not necessary because of the use of Metadata above
user_name = db.Column('USER_NAME', db.String(250))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment