[sqlalchemy] Re: SQLACODEGEN + VSCODE + Intellisense not working.

2018-05-11 Thread Jeremy Flowers


Also tried this in extrapaths - no joy either: 

${workspaceRoot}
Per this thread  



On Saturday, 12 May 2018 00:32:40 UTC+1, Jeremy Flowers wrote:
>
> I've also been looking at here 
>  in the 
> hope of finding a solution.
> I tried setting this in the VS Code (Version 1.23.1) 'User Settings' tab 
> (File -> Preferences -> Settings) 
> "python.autoComplete.extraPaths": ["c:\\opt\\tidalconversion\tidal.py"]
>
> The exiting and relaunching IDE. Alas that didn't work either..
>

-- 
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] Re: SQLACODEGEN + VSCODE + Intellisense not working.

2018-05-11 Thread Jeremy Flowers
I've also been looking at here 
 in the hope 
of finding a solution.
I tried setting this in the VS Code (Version 1.23.1) 'User Settings' tab 
(File -> Preferences -> Settings) 
"python.autoComplete.extraPaths": ["c:\\opt\\tidalconversion\tidal.py"]

The exiting and relaunching IDE. Alas that didn't work either..

-- 
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] is it possible to make load_only local to an object only and/or avoid the identity map and/or not available via `get`?

2018-05-11 Thread Jonathan Vanasco
I tracked down a pattern that has been causing some bottleneck issues in an 
app.  I'm hoping there may be a way to handle this, but for once I don't 
expect there to be!

The problem arises when I fetch a specific "light" query with joined 
objects (however toplevel objects have the same issue). 

   foo = 
s.query(Foo).options(sqlalchemy.orm.joinedload('bar').load_only('name')).filter(Foo.id==2)

Later on, I might request the same bar I had loaded using `get`

 bar = s.query(Bar).get(id=22)

If I happen to grab a Bar that was loaded off a load_only, every time i 
touch an attribute I talk to the database - which is what causes my slowup.

I don't necessarily want to call expunge_all() or expunge, because I might 
still access that object.  


-- 
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] How to formulate a query using sqlalchemy ORM constructs that calculates the difference between entries in rows

2018-05-11 Thread Mike Bayer
On Fri, May 11, 2018 at 3:17 PM, Björn Nadrowski  wrote:
>
>
> Hi Mike,
> that looks very good,
>
> However, I am still left with three problems:
>
> a) the query returns "None" in the datediff column. It seems that the
> strings "datetime" and "PreviousDate" are somehow not recognized. When I
> replace
> "(
> func.julianday("datetime") -
> func.julianday("PreviousDate")).label("datediff") "
> by
> (max_subq).label("datediff")
>
> then I do get a non-None result.

does the raw SQL statement previously w/ the julianday function work?
 I'm not familiar with this function on SQLite.

The constructed SQL is:
> SELECT "T".id, "T".datetime, "T".val, "T".info, (SELECT max("T2".datetime)
> AS max_1
>   FROM "testTable" AS "T2", "testTable" AS "T1"
>   WHERE "T2".info = "T1".info AND "T2".datetime < "T1".datetime) AS datediff
>   FROM (SELECT "T1".id AS id, "T1".datetime AS datetime, "T1".val AS val,
> "T1".info AS info, (SELECT max("T2".datetime) AS max_1
>   FROM "testTable" AS "T2"
>   WHERE "T2".info = "T1".info AND "T2".datetime < "T1".datetime) AS
> "PreviousDate"
>   FROM "testTable" AS "T1") AS "T"
>
> The "datediff" column contains, in this case, the value "2018-01-03" in each
> of the 6 rows.
>
> b) I do not know what the "correlate(T1)" statement does. I looked up the
> docs for correlate but was unable to find out what that really does.
> The SQL produced by your code is identical regardless of whether
> correlate(T1) is used or not.

then you can omit it, correlation is automatic if there are no
correlation directives given, documentation at
http://docs.sqlalchemy.org/en/latest/core/tutorial.html#correlated-subqueries


>
> c) The code is still sqlite-specific (use of julianday()). Suppose I find
> out the  reason why the code does not work and succeed reproducing the
> desired output. Then the code would still be SQLite-specific and not generic
> which is the main reason for using sqlalchemy. What do I have to do to make
> it databse-backend-indpeendent?

unfortunately date arithmetic is complicated and extremely different
on pretty much every database, and SQLAlchemy doesn't have an
abstraction layer for date arithmetic functions.  What I usually do is
figure out the correct expression for each of the databases I'm
targeting, then I build custom function, example at
http://docs.sqlalchemy.org/en/latest/core/compiler.html#utc-timestamp-function
.


>
> Thanks for your help,
> Bjoern
>
>
>>
>> no need, can you try this query?
>>
>> T2 = aliased(CTestTable, name="T2")
>> T1 = aliased(CTestTable, name="T1")
>>
>> max_subq = session.query(
>> func.max(T2.datetime)
>> ).filter(T2.info == T1.info).filter(
>> T2.datetime < T1.datetime).correlate(T1).label("PreviousDate")
>>
>> subq = session.query(
>> T1.id, T1.datetime, T1.val, T1.info, max_subq).subquery("T")
>> q = session.query(
>> subq.c.id, subq.c.datetime, subq.c.val, subq.c.info,
>> (
>> func.julianday("datetime") -
>> func.julianday("PreviousDate")).label("datediff")
>> ).select_from(
>> subq
>> )
>>
>> q.all()
>>
>> log output is:
>>
>> SELECT "T".id AS "T_id", "T".datetime AS "T_datetime", "T".val AS
>> "T_val", "T".info AS "T_info", julianday(?) - julianday(?) AS datediff
>> FROM (SELECT "T1".id AS id, "T1".datetime AS datetime, "T1".val AS
>> val, "T1".info AS info, (SELECT max("T2".datetime) AS max_1
>> FROM "testTable" AS "T2"
>> WHERE "T2".info = "T1".info AND "T2".datetime < "T1".datetime) AS
>> "PreviousDate"
>> FROM "testTable" AS "T1") AS "T"
>> 2018-05-03 20:11:30,082 INFO sqlalchemy.engine.base.Engine
>> ('datetime', 'PreviousDate')
>>
>>
>> is that right?  note the uppercase names need to be quoted, literal
>> values are turned into bind parameters, etc.
>>
>>
> --
> 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 

Re: [sqlalchemy] How to formulate a query using sqlalchemy ORM constructs that calculates the difference between entries in rows

2018-05-11 Thread Björn Nadrowski


Hi Mike, 
that looks very good, 

However, I am still left with three problems:

a) the query returns "None" in the datediff column. It seems that the 
strings "datetime" and "PreviousDate" are somehow not recognized. When I 
replace 
"( 
func.julianday("datetime") - 
func.julianday("PreviousDate")).label("datediff") "
by 
(max_subq).label("datediff") 

then I do get a non-None result. The constructed SQL is:
SELECT "T".id, "T".datetime, "T".val, "T".info, (SELECT max("T2".datetime) 
AS max_1 
  FROM "testTable" AS "T2", "testTable" AS "T1" 
  WHERE "T2".info = "T1".info AND "T2".datetime < "T1".datetime) AS 
datediff 
  FROM (SELECT "T1".id AS id, "T1".datetime AS datetime, "T1".val AS val, 
"T1".info AS info, (SELECT max("T2".datetime) AS max_1 
  FROM "testTable" AS "T2" 
  WHERE "T2".info = "T1".info AND "T2".datetime < "T1".datetime) AS 
"PreviousDate" 
  FROM "testTable" AS "T1") AS "T"

The "datediff" column contains, in this case, the value "2018-01-03" in 
each of the 6 rows.

b) I do not know what the "correlate(T1)" statement does. I looked up the 
docs for correlate but was unable to find out what that really does. 
The SQL produced by your code is identical regardless of whether 
correlate(T1) is used or not.

c) The code is still sqlite-specific (use of julianday()). Suppose I find 
out the  reason why the code does not work and succeed reproducing the 
desired output. Then the code would still be SQLite-specific and not 
generic which is the main reason for using sqlalchemy. What do I have to do 
to make it databse-backend-indpeendent?

Thanks for your help, 
Bjoern

 

> no need, can you try this query? 
>
> T2 = aliased(CTestTable, name="T2") 
> T1 = aliased(CTestTable, name="T1") 
>
> max_subq = session.query( 
> func.max(T2.datetime) 
> ).filter(T2.info == T1.info).filter( 
> T2.datetime < T1.datetime).correlate(T1).label("PreviousDate") 
>
> subq = session.query( 
> T1.id, T1.datetime, T1.val, T1.info, max_subq).subquery("T") 
> q = session.query( 
> subq.c.id, subq.c.datetime, subq.c.val, subq.c.info, 
> ( 
> func.julianday("datetime") - 
> func.julianday("PreviousDate")).label("datediff") 
> ).select_from( 
> subq 
> ) 
>
> q.all() 
>
> log output is: 
>
> SELECT "T".id AS "T_id", "T".datetime AS "T_datetime", "T".val AS 
> "T_val", "T".info AS "T_info", julianday(?) - julianday(?) AS datediff 
> FROM (SELECT "T1".id AS id, "T1".datetime AS datetime, "T1".val AS 
> val, "T1".info AS info, (SELECT max("T2".datetime) AS max_1 
> FROM "testTable" AS "T2" 
> WHERE "T2".info = "T1".info AND "T2".datetime < "T1".datetime) AS 
> "PreviousDate" 
> FROM "testTable" AS "T1") AS "T" 
> 2018-05-03 20:11:30,082 INFO sqlalchemy.engine.base.Engine 
> ('datetime', 'PreviousDate') 
>
>
> is that right?  note the uppercase names need to be quoted, literal 
> values are turned into bind parameters, etc. 
>
>
>

-- 
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] SQLACODEGEN + VSCODE + Intellisense not working.

2018-05-11 Thread Jeremy Flowers
I have some code in VS Code...

  jobrow = session.query(Jobmst).filter(Jobmst.jobmst_id==job['jobmst_id']).
first()



Jobmst is imported from a single module I've created called tidal.py

jobrow is an instance of Jobmst...

But I can't select any of the columns.

I've tried 

http://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/quickstart.html
 (Steps 
1..3 -> Then python install .\dist\.tar.gz

After reading both these:

https://stackoverflow.com/a/30608672/495157

https://stackoverflow.com/questions/31384639/what-is-pythons-site-packages-directory


Then found that pip install rather than python install is way to go...

Since uninstalling causes issues per this comment:

https://stackoverflow.com/questions/37856569/pip-uninstall-working-but-giving-error


have just deleted folders in the.

\Lib\site-packages folder 

an egg.info folder and module folder)



I have this in my setup.py:
from distutils.core import setup
setup(
name='TidalConversion',
version='0.1dev',
packages=['tidalconversion',],
license='Creative Commons Attribution-Noncommercial-Share Alike license'
,
long_description=open('README.txt').read(),
)


I have this in my __init__.py:
#!/usr/bin/env python
import os
from tidal import *
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
engine = create_engine(os.environ['DATABASE_URL'], echo=False) #echo='debug'
Session = sessionmaker(bind=engine)


tidal is the file that contains the sqlacodegen generated classes - 
including the Jobmst class I can't get Intellisense on.


In my main code I have..
from tidalconversion import Session, engine, Jobmst

(tidalconversion is my module name I'm packaging stuff up in)


This is what my folder structure looks like:




*Can someone advise what i have to do in order to get Intellisense working 
in VS Code?*

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