[sqlalchemy] setters and getters on an automapped table

2016-08-25 Thread Robert Minsk
I am using automap_base to reflect a table.

metadata = MetaData()
metadata.reflect(bind=engine, only=['hosts'])
automap = automap_base(metadata=metadata)
automap.prepare()

Hosts = automap.classes.hosts

The mac_address column in Hosts is  binary and would like to to replace the 
mac_address with some sort of getter/setter to decode/encode the address. 
 I have not found an example of doing this with an automapped table.  Is 
there a easy way to do this?

-- 
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] Checking for an object in the database before adding a potential duplicate

2016-08-25 Thread Kovas Palunas
 

Hi everyone,


I have an database setup where i have two tables/objects that are 
associated via two many to many relationships (with association tables).  I 
would 
like to find a way to quickly query for the existence of one of the 
objects, which is partially defined by its associations with the other 
object.  This is primarily so I can check to see if a given object exists 
before inserting a potential duplicate into my database.  


As an example (AX and BX are objects, [B1, B2, ...] is a list of multiple B 
instances, --X--> denotes a relationship, and X is some number denoting a 
specific object or relationship):


A1 --1--> [B1, B2, B3]

A1 --2--> [B4, B2, B5]

A2 --3--> [B6, B1, B7]




Currently I've thought of two (sub-par) solutions: 

1 - Use associations to compute a hash, which is stored in the database and 
used to distinguish the object

2 - Read the whole database into python objects and use those object's 
lists of the other object to compare


I've implemented the first solution and it works, but feels clunky.  Is 
there a better way to do this?  


Thanks!


 - Kovas

-- 
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] Column order with declarative base and @declared_attr

2016-08-25 Thread Mike Bayer



On 08/25/2016 04:37 PM, Seth P wrote:

If I understand what you're saying, the problem is that set
_creation_order() specifies an ordering across all columns from all
mixins. But shouldn't it suffice to specify the "local" ordering of the
columns within a given mixin, and then process the mixins in __mro__ order?


the way set_creation_order() works is by assigning a counter to an 
object when it is actually created, not when it is encountered in a 
class definition.


That's how we get around:

class Foo(object):
   attr_one = some_attr("im first!")

   attr_two = some_attr("im second!")

   attr_three = some_attr("im third!")

When we get a Python metaclass for the above, attr_one/two/three are all 
in an unordered dict().  So instead, there's a counter that was set up 
when some_attr() was actually called.


That approach doesn't really work here:

class Foo(object):
   @some_attr("im first!")
   def return_a_thing(self):
  return Thing()

   @some_attr("im second!")
   def return_another_thing(self):
  return Thing()

   @some_attr("im third!")
   def return_a_third_thing(self):
  return Thing()


that is, while we can still give a counter to some_attr(), the thing 
that is calling those methods also has to be invoked in that order, 
because we really want each Thing() to have the ordering, and they've 
yet to be created.


You can of course try to make each Thing() with a hardcoded ordering:


class Foo(object):
   @some_attr("im first!")
   def return_a_thing(self):
  return Thing(hardcode_ordering=100)

   @some_attr("im second!")
   def return_another_thing(self):
  return Thing(hardcode_ordering=200)

   @some_attr("im third!")
   def return_a_third_thing(self):
  return Thing(hardcode_ordering=300)

if you want to go that approach you can assign _creation_order to each 
Column you're creating, but those numbers have to all be what you want 
in relation to all the other columns being set up.


Overall in SQL it really shouldn't matter what order columns are set up 
in. If you *really* need this then I'd suggest using inner __table__ 
style: 
http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/declarative/table_config.html#using-a-hybrid-approach-with-table










(FWIW I worked around my particular problem by making the Columns
non-@declared_attr, eliminating ForeignKey parameters (which are
cls-dependent), and creating cls-dependent ForeignKeyConstraints in a
cls-dependent __table_args__.)





On Thu, Aug 25, 2016 at 4:24 PM -0400, "Mike Bayer"
> wrote:

the @declarative_attr object would need util.set_creation_order()
applied and the _MapperConfig._scan_attributes() would need to take this
into account.  However, it would not behave well across multiple mixins.
  The mixins must be scanned in __mro__ order first.   So it would be of
limited use for there to be an ordering under @declared_attr.


On 08/25/2016 02:46 PM, Seth P wrote:
> I was just bitten by this issue. Is it still the case that there is no 
way to specify the order of two columns declared in a mixin using @declared_attr?
>

--
You received this message because you are subscribed to a topic in the Google Groups 
"sqlalchemy" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/sqlalchemy/OA-n_pY0tuM/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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.


--
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] Re: Get nested query from Exists clause

2016-08-25 Thread Mike Bayer



On 08/25/2016 03:17 PM, Dominik George wrote:

To be more precise:

I have a query like this one:

|
session.query(osmalchemy.node).filter(osmalchemy.node.tags.any(key="name",value="Grill-Corner")).all()
|

It ultimately compiles to this QL expression:

|
query =SELECT osm_nodes.element_id AS
osm_nodes_element_id,osm_elements.element_id AS
osm_elements_element_id,osm_elements.osmalchemy_updated AS
osm_elements_osmalchemy_updated,osm_elements.type AS
osm_elements_type,osm_elements.id AS
osm_elements_id,osm_elements.version AS
osm_elements_version,osm_elements.changeset AS
osm_elements_changeset,osm_elements.user AS
osm_elements_user,osm_elements.uid AS
osm_elements_uid,osm_elements.visible AS
osm_elements_visible,osm_elements.timestamp AS
osm_elements_timestamp,osm_nodes.latitude AS
osm_nodes_latitude,osm_nodes.longitude AS osm_nodes_longitude
FROM osm_elements JOIN osm_nodes ON osm_elements.element_id
=osm_nodes.element_id
WHERE EXISTS (SELECT 1
FROM osm_elements_tags
WHERE osm_elements.element_id =osm_elements_tags.element_id AND (EXISTS
(SELECT 1
FROM osm_tags
WHERE osm_tags.tag_id =osm_elements_tags.tag_id AND osm_tags.value =?AND
osm_tags."key"=?)))
|

I want to programmatically get to the last two comparisons, i.e. the
criterion of the .any() call in the initial query.

I am receiving this query in a before_compile trigger in a library using
SQLAlchemy.


so before_compile() does not receive a core Select, it receives the 
Query before anything has been done to it yet.  However, any() generate 
a SELECT.  So you need to look in both.


You can generically iterate through the elements of a Core element using 
get_children():



@event.listens_for(Query, "before_compile")
def show_any_filter(query):
stack = [query._criterion]

while stack:
elem = stack.pop(-1)
if isinstance(elem, sql.selectable.Select):
print("WHERECLAUSE: %s" % elem._whereclause)
else:
stack.extend(elem.get_children())








-nik

--
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.


--
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] Column order with declarative base and @declared_attr

2016-08-25 Thread Seth P
If I understand what you're saying, the problem is that set _creation_order() 
specifies an ordering across all columns from all mixins. But shouldn't it 
suffice to specify the "local" ordering of the columns within a given mixin, 
and then process the mixins in __mro__ order?
(FWIW I worked around my particular problem by making the Columns 
non-@declared_attr, eliminating ForeignKey parameters (which are 
cls-dependent), and creating cls-dependent ForeignKeyConstraints in a 
cls-dependent __table_args__.)






On Thu, Aug 25, 2016 at 4:24 PM -0400, "Mike Bayer"  
wrote:










the @declarative_attr object would need util.set_creation_order() 
applied and the _MapperConfig._scan_attributes() would need to take this 
into account.  However, it would not behave well across multiple mixins. 
  The mixins must be scanned in __mro__ order first.   So it would be of 
limited use for there to be an ordering under @declared_attr.


On 08/25/2016 02:46 PM, Seth P wrote:
> I was just bitten by this issue. Is it still the case that there is no way to 
> specify the order of two columns declared in a mixin using @declared_attr?
>

-- 
You received this message because you are subscribed to a topic in the Google 
Groups "sqlalchemy" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/sqlalchemy/OA-n_pY0tuM/unsubscribe.
To unsubscribe from this group and all its topics, 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.





-- 
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] Google Bigquery support

2016-08-25 Thread Mike Bayer



On 08/25/2016 11:26 AM, rla...@fastly.com wrote:

Hello all,

I overrided that method as you suggested, and included placeholders for
the other ones being overloaded by calchipan. The reflection functions
now work, and I decided to use the same mechanism as calchipan for DDL
compilation (instantiating a Resolver object that is then passed to the
dbapi implementation). Hoever I've hit another snag that maybe you guys
have seen before.

The current state of the code can be checked out here:

https://github.com/rlanda/sqlalchemy-bigquery/tree/master/sqlalchemy_bigquery

To start filling in the CREATE functionality, I'm using this toy example:


metadata = MetaData(engine)

users = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String),
Column('age', Integer),
Column('fullname', String),
)
users.create()

I expected this to trigger *visit_create_table *in the DDL compiler,
which would return a *Resolver* object that would be provided to the
*execute* method in the *Cursor* implementation in *dbapi*. However,
this is not happening - instead, it seems that the default execute
method is being triggered, instead of that in dbapi. Since that method
expects a string instead of the Resover object, it complains. The
exception I am getting is:


Traceback (most recent call last):

  File "./test_bq.py", line 39, in 

users.create()

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/sql/schema.py", line
747, in create

checkfirst=checkfirst)

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py",
line 1920, in _run_visitor

conn._run_visitor(visitorcallable, element, **kwargs)

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py",
line 1529, in _run_visitor

**kwargs).traverse_single(element)

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/sql/visitors.py",
line 126, in traverse_single

return meth(obj, **kw)

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/sql/ddl.py",
line 767, in visit_table

include_foreign_key_constraints=include_foreign_key_constraints

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py",
line 947, in execute

return meth(self, multiparams, params)

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/sql/ddl.py",
line 68, in _execute_on_connection

return connection._execute_ddl(self, multiparams, params)

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py",
line 1004, in _execute_ddl

compiled

  File
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py",
line 1125, in _execute_context

util.text_type(statement), parameters,

TypeError: coercing to Unicode: need string or buffer,
CreateTableResolver found



that text_type() call is inside of the part where it's trying to throw 
an exception.   you'll want to give your Resolver object a __str__() 
method so that unicode() reports something meaningful.








Any ideas on how invoke the correct execute method?

Thanks again!
Raul



On Friday, August 19, 2016 at 3:14:00 PM UTC+1, Mike Bayer wrote:



On 08/19/2016 06:37 AM, rla...@fastly.com  wrote:
> Hello all,
>
> I have implemented the first stab at a PEP 249 adaptor layer for
> BigQuery and it seems to work well. It is possible to create an
> engine/connection/cursor, submit an SQL query and get results back
(only
> SELECT statements for now, API commands will come later). I have
moved
> on to changing the DDL and statement compilers to conform to
BigQuery's
> standard SQL dialect:
>
> https://cloud.google.com/bigquery/sql-reference/query-syntax

>
> I hit an immediate hurdle and I am not sure if it is because the
Dialect
> object I created is incorrect or because the PEP 249 adapter is
behaving
> in an unexpected way. Basically, upon connection SQL alchemy will
fire
> some test queries (afaiu to detect whether column names support
> unicode), one of which is being rendered as
>
> SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
>
>
> The problem is that BigQuery does not support VARCHAR. I have already
> added a colspecs dictionary to my new dialect object, with many
common
> data types mapped to their BgQuery equivalents:


The method that's calling this test and others is in
sqlalchemy/engine/default -> DefaultDialect.initialize().   You should
override that whole method and do away with all the things it's trying
to check there, as calchipan does:


https://bitbucket.org/zzzeek/calchipan/src/86ef380c572b9c1b8186278446a9b4952a538f97/calchipan/base.py?at=master=file-view-default#base.py-45


Re: [sqlalchemy] Column order with declarative base and @declared_attr

2016-08-25 Thread Mike Bayer
the @declarative_attr object would need util.set_creation_order() 
applied and the _MapperConfig._scan_attributes() would need to take this 
into account.  However, it would not behave well across multiple mixins. 
 The mixins must be scanned in __mro__ order first.   So it would be of 
limited use for there to be an ordering under @declared_attr.



On 08/25/2016 02:46 PM, Seth P wrote:

I was just bitten by this issue. Is it still the case that there is no way to 
specify the order of two columns declared in a mixin using @declared_attr?



--
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] Re: Get nested query from Exists clause

2016-08-25 Thread Dominik George
To be more precise:

I have a query like this one:

session.query(osmalchemy.node).filter(osmalchemy.node.tags.any(key="name", 
value="Grill-Corner")).all()

It ultimately compiles to this QL expression:

query = SELECT osm_nodes.element_id AS osm_nodes_element_id, 
osm_elements.element_id 
AS osm_elements_element_id, osm_elements.osmalchemy_updated AS 
osm_elements_osmalchemy_updated, osm_elements.type AS osm_elements_type, 
osm_elements.id AS osm_elements_id, osm_elements.version AS 
osm_elements_version, osm_elements.changeset AS osm_elements_changeset, 
osm_elements.user AS osm_elements_user, osm_elements.uid AS osm_elements_uid
, osm_elements.visible AS osm_elements_visible, osm_elements.timestamp AS 
osm_elements_timestamp, osm_nodes.latitude AS osm_nodes_latitude, 
osm_nodes.longitude 
AS osm_nodes_longitude 
FROM osm_elements JOIN osm_nodes ON osm_elements.element_id = 
osm_nodes.element_id 

WHERE EXISTS (SELECT 1 
FROM osm_elements_tags 
WHERE osm_elements.element_id = osm_elements_tags.element_id AND (EXISTS 
(SELECT 
1 
FROM osm_tags 
WHERE osm_tags.tag_id = osm_elements_tags.tag_id AND osm_tags.value = ? AND 
osm_tags."key" = ?)))

I want to programmatically get to the last two comparisons, i.e. the 
criterion of the .any() call in the initial query.

I am receiving this query in a before_compile trigger in a library using 
SQLAlchemy.

-nik

-- 
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] Get nested query from Exists clause

2016-08-25 Thread Dominik George
Hi,

Am Montag, 15. August 2016 15:32:35 UTC+2 schrieb Mike Bayer:
>
>
> nothing is string-compiled at that point, everything is just nested 
> inside.  the Exists() should have something like "element" inside of it 
> (look in its __dict__) that is the underlying Selectable. 
>
>
>
.element is a FromGrouping, probably because it's "EXISTS (SELECT 1 …)". 
The FromGrouping again has a .element, and a .get_children(). 
get_children() returns a tuple with one Select object, which I guess is the 
nested SELECT statement, but that unfortunately does not have a 
.whereclause attribute like the initial Query object.

How do I get to the WHERE clause of the nested SELECT statement?

-nik 

-- 
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] Column order with declarative base and @declared_attr

2016-08-25 Thread Seth P
I was just bitten by this issue. Is it still the case that there is no way to 
specify the order of two columns declared in a mixin using @declared_attr?

-- 
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] Google Bigquery support

2016-08-25 Thread rlanda
Hello all,

I overrided that method as you suggested, and included placeholders for the 
other ones being overloaded by calchipan. The reflection functions now 
work, and I decided to use the same mechanism as calchipan for DDL 
compilation (instantiating a Resolver object that is then passed to the 
dbapi implementation). Hoever I've hit another snag that maybe you guys 
have seen before.

The current state of the code can be checked out here:

https://github.com/rlanda/sqlalchemy-bigquery/tree/master/sqlalchemy_bigquery

To start filling in the CREATE functionality, I'm using this toy example:


metadata = MetaData(engine)

users = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String),
Column('age', Integer),
Column('fullname', String),
)
users.create()

I expected this to trigger *visit_create_table *in the DDL compiler, which 
would return a *Resolver* object that would be provided to the *execute* 
method in the *Cursor* implementation in *dbapi*. However, this is not 
happening - instead, it seems that the default execute method is being 
triggered, instead of that in dbapi. Since that method expects a string 
instead of the Resover object, it complains. The exception I am getting is:


Traceback (most recent call last):

  File "./test_bq.py", line 39, in 

users.create()

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/sql/schema.py", 
line 747, in create

checkfirst=checkfirst)

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py", 
line 1920, in _run_visitor

conn._run_visitor(visitorcallable, element, **kwargs)

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py", 
line 1529, in _run_visitor

**kwargs).traverse_single(element)

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/sql/visitors.py", 
line 126, in traverse_single

return meth(obj, **kw)

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/sql/ddl.py", line 
767, in visit_table

include_foreign_key_constraints=include_foreign_key_constraints

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py", 
line 947, in execute

return meth(self, multiparams, params)

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/sql/ddl.py", line 
68, in _execute_on_connection

return connection._execute_ddl(self, multiparams, params)

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py", 
line 1004, in _execute_ddl

compiled

  File 
"/Users/rlanda/Workspace/Python/sqlalchemy/lib/sqlalchemy/engine/base.py", 
line 1125, in _execute_context

util.text_type(statement), parameters,

TypeError: coercing to Unicode: need string or buffer, CreateTableResolver 
found


Any ideas on how invoke the correct execute method?

Thanks again!
Raul



On Friday, August 19, 2016 at 3:14:00 PM UTC+1, Mike Bayer wrote:
>
>
>
> On 08/19/2016 06:37 AM, rla...@fastly.com  wrote: 
> > Hello all, 
> > 
> > I have implemented the first stab at a PEP 249 adaptor layer for 
> > BigQuery and it seems to work well. It is possible to create an 
> > engine/connection/cursor, submit an SQL query and get results back (only 
> > SELECT statements for now, API commands will come later). I have moved 
> > on to changing the DDL and statement compilers to conform to BigQuery's 
> > standard SQL dialect: 
> > 
> > https://cloud.google.com/bigquery/sql-reference/query-syntax 
> > 
> > I hit an immediate hurdle and I am not sure if it is because the Dialect 
> > object I created is incorrect or because the PEP 249 adapter is behaving 
> > in an unexpected way. Basically, upon connection SQL alchemy will fire 
> > some test queries (afaiu to detect whether column names support 
> > unicode), one of which is being rendered as 
> > 
> > SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 
> > 
> > 
> > The problem is that BigQuery does not support VARCHAR. I have already 
> > added a colspecs dictionary to my new dialect object, with many common 
> > data types mapped to their BgQuery equivalents: 
>
>
> The method that's calling this test and others is in 
> sqlalchemy/engine/default -> DefaultDialect.initialize().   You should 
> override that whole method and do away with all the things it's trying 
> to check there, as calchipan does: 
>
>
> https://bitbucket.org/zzzeek/calchipan/src/86ef380c572b9c1b8186278446a9b4952a538f97/calchipan/base.py?at=master=file-view-default#base.py-45
>  
>
> Although I would say that on the SQLAlchemy side, 
> _check_unicode_returns() should likely be a method that can raise 
> NotImplementedError() individually like the rest of the tests called 
> within the base initialize(). 
>
>
>
>
> > 
> > 
> > colspecs = { 
> > 
> > types.Unicode: BQString, 
> > 
> > types.Integer: BQInteger, 
> > 
> > types.SmallInteger: BQInteger, 
> > 
> > types.Numeric: BQFloat, 
> > 

Re: [sqlalchemy] Re: Abusing a string column as list of foreign keys (own relationship class, based on DependencyProcessor?)

2016-08-25 Thread Mike Bayer



On 08/25/2016 07:50 AM, Torsten Landschoff wrote:

Hi Mike,

On Wednesday, August 24, 2016 at 1:27:42 PM UTC+2, Mike Bayer wrote:


if you've already solved the problem I'd rather not get into it :)


I am still curious about the inner workins of the DependencyProcessors
of sqlalchemy and how it would be possible to implement a custom
relationship property.
Not that I would make use of it currently. :-)



well dependencyprocessor is about doing the objects in the right order, 
and about invoking a command to "sync" important attributes from one 
side to the other, which means copying the PK of one object to the FK of 
another.  I guess in this case we'd be "copying" the PK of related 
objects into the local object's comma-separated list of keys.   From 
that perspective this is not much of a "DependencyProcessor" problem 
because you have this local attribute that just contains a view 
(comma-separated-list of keys) of a collection attribute on the same 
object.   That is, I don't see much of a "topological" problem here if 
I'm understanding correctly.   Copy-on-write is done by an attribute 
event, object is written therefore we set a flag, in before_flush() we 
copy all the objects that need to be copied-on-write, then I think you 
have the after_flush there to update the parent object.you can set 
up Bundle.members there also.




Greetings, Torsten

--
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.


--
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] Re: Abusing a string column as list of foreign keys (own relationship class, based on DependencyProcessor?)

2016-08-25 Thread Torsten Landschoff
Hi Mike,

On Wednesday, August 24, 2016 at 1:27:42 PM UTC+2, Mike Bayer wrote:
 

> if you've already solved the problem I'd rather not get into it :) 
>
>
I am still curious about the inner workins of the DependencyProcessors of 
sqlalchemy and how it would be possible to implement a custom relationship 
property.
Not that I would make use of it currently. :-)

Greetings, Torsten

-- 
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.