Re: [sqlalchemy] quote=False for all columns in table
Perfect. Thank you! On Friday, June 30, 2017 at 5:41:33 PM UTC-4, Mike Bayer wrote: > > > from sqlalchemy import Column, String, Integer, create_engine > from sqlalchemy.orm import Session > from sqlalchemy.ext.declarative import declarative_base > from sqlalchemy import event > > Base = declarative_base() > > > @event.listens_for(Column, "before_parent_attach") > def _attach_column(column, table, **kw): > column.name = column.name.lower() > > > class A(Base): > __tablename__ = 'a' > myId = Column(Integer, primary_key=True) > someData = Column(String) > maxInterval = Column(Integer) > > > e = create_engine("sqlite://", echo=True) > Base.metadata.create_all(e) > > s = Session(e) > > s.add(A(someData='sasefd', maxInterval=5)) > s.commit() > > print(s.query(A.someData, A.maxInterval)).all() > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] quote=False for all columns in table
On Fri, Jun 30, 2017 at 5:10 PM, Seth P wrote: > I'm just accessing a vendor-provided Oracle database. The database itself is > all upper(lower?) case (I'm new to Oracle), case insensitive if unquoted names are used. whereas I want my declarative > model columns to be camelCase (and the emitted SQL to be unquoted camelCase) once you emit the names case insensitively, Oracle will forever show them as COLUMNNAME after that. your casing will be lost on the database so there is no reason to send over a camelCase name to Oracle if it isn't to be quoted. if you'd like your *Python code* to use camelCase, that is easy; name the declarative attribute with your camelCase name (though note this violates pep8), and ensure the column name is all lower case. Assuming you are not using reflection or automap (which if you are using a pre-fab database might be a lot less trouble), the easiest way is to intercept the name when the column is being attached. I know this is 95% the same as setting the "quote" flag, but it's better to set the column to be "case insensitive", e.g. set the name to all lower case which is what SQLAlchemy uses to determine case sensitivity of a name, rather than unconditionally quoting. When you have a column named "order" or "user" or something like that, you'll be thankful: from sqlalchemy import Column, String, Integer, create_engine from sqlalchemy.orm import Session from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import event Base = declarative_base() @event.listens_for(Column, "before_parent_attach") def _attach_column(column, table, **kw): column.name = column.name.lower() class A(Base): __tablename__ = 'a' myId = Column(Integer, primary_key=True) someData = Column(String) maxInterval = Column(Integer) e = create_engine("sqlite://", echo=True) Base.metadata.create_all(e) s = Session(e) s.add(A(someData='sasefd', maxInterval=5)) s.commit() print(s.query(A.someData, A.maxInterval)).all() > to match the vendor's documentation. I could make the column names all lower > case, but would like to use camelCase if there's an easy way to do it. Only > annoying thing about a custom my_column() is that I'd have to specify the > name argument explicitly for each column, right? > > On Friday, June 30, 2017 at 5:05:15 PM UTC-4, Mike Bayer wrote: >> >> On Fri, Jun 30, 2017 at 4:31 PM, Seth P wrote: >> > Is there a way (when using declarative) to specify that all the columns >> > of a >> > table should use quote=False without specifying it explicitly for each >> > column? >> >> Easiest is just to call your own my_column(...) function that sets the >> flag as you'd like, but setting quote=False unconditionally is a bad >> idea and you shouldn't ever have to do that. This sounds like you >> are communicating with some special database backend for which you'd >> be better off building a real dialect for it. >> >> >> > I've tried setting __table_args__ = { 'quote_schema': False, 'quote': >> > False >> > }, but that just affects the schema and table name, not the column name. >> > >> > -- >> > SQLAlchemy - >> > The Python SQL Toolkit and Object Relational Mapper >> > >> > http://www.sqlalchemy.org/ >> > >> > To post example code, please provide an MCVE: Minimal, Complete, and >> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full >> > description. >> > --- >> > You received this message because you are subscribed to the Google >> > Groups >> > "sqlalchemy" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> > an >> > email to sqlalchemy+...@googlegroups.com. >> > To post to this group, send email to sqlal...@googlegroups.com. >> > Visit this group at https://groups.google.com/group/sqlalchemy. >> > For more options, visit https://groups.google.com/d/optout. > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubs
Re: [sqlalchemy] quote=False for all columns in table
I'm just accessing a vendor-provided Oracle database. The database itself is all upper(lower?) case (I'm new to Oracle), whereas I want my declarative model columns to be camelCase (and the emitted SQL to be unquoted camelCase) to match the vendor's documentation. I could make the column names all lower case, but would like to use camelCase if there's an easy way to do it. Only annoying thing about a custom my_column() is that I'd have to specify the name argument explicitly for each column, right? On Friday, June 30, 2017 at 5:05:15 PM UTC-4, Mike Bayer wrote: > > On Fri, Jun 30, 2017 at 4:31 PM, Seth P > > wrote: > > Is there a way (when using declarative) to specify that all the columns > of a > > table should use quote=False without specifying it explicitly for each > > column? > > Easiest is just to call your own my_column(...) function that sets the > flag as you'd like, but setting quote=False unconditionally is a bad > idea and you shouldn't ever have to do that. This sounds like you > are communicating with some special database backend for which you'd > be better off building a real dialect for it. > > > > I've tried setting __table_args__ = { 'quote_schema': False, 'quote': > False > > }, but that just affects the schema and table name, not the column name. > > > > -- > > SQLAlchemy - > > The Python SQL Toolkit and Object Relational Mapper > > > > http://www.sqlalchemy.org/ > > > > To post example code, please provide an MCVE: Minimal, Complete, and > > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > > description. > > --- > > You received this message because you are subscribed to the Google > Groups > > "sqlalchemy" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to sqlalchemy+...@googlegroups.com . > > To post to this group, send email to sqlal...@googlegroups.com > . > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] quote=False for all columns in table
On Fri, Jun 30, 2017 at 4:31 PM, Seth P wrote: > Is there a way (when using declarative) to specify that all the columns of a > table should use quote=False without specifying it explicitly for each > column? Easiest is just to call your own my_column(...) function that sets the flag as you'd like, but setting quote=False unconditionally is a bad idea and you shouldn't ever have to do that. This sounds like you are communicating with some special database backend for which you'd be better off building a real dialect for it. > I've tried setting __table_args__ = { 'quote_schema': False, 'quote': False > }, but that just affects the schema and table name, not the column name. > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] quote=False for all columns in table
Is there a way (when using declarative) to specify that all the columns of a table should use quote=False without specifying it explicitly for each column? I've tried setting __table_args__ = { 'quote_schema': False, 'quote': False }, but that just affects the schema and table name, not the column name. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.