Re: mapping objects

2014-02-02 Thread Rita
Thanks for the response Cameron. No amount of 'googling' could provide me
with that caliber response :-)

So, it seems regardless I would need a database.





On Sun, Feb 2, 2014 at 1:58 AM, Cameron Simpson c...@zip.com.au wrote:

 On 01Feb2014 20:46, Rita rmorgan...@gmail.com wrote:
  I want to learn more about ORMs so I stumbled upon, SqlAlchemy.
 
  If i had a JSON document (or XML, CSV, etc.._) is it possible to convert
 it
  to a SQLAlchemy objects? I like the ability to query/filter (
 
 http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#common-filter-operators
 )
   the
  data assuming I set up the proper schema.

 Well, not as directly as you might hope. As I recall, SQLAlchemy
 ORMs provide an easy way to make objects representing database
 entities and whose methods automatically drive the necessary SQL
 actions to manipulate them.

 On that basis, you won't get anywhere without loading up the
 JSON/XML/etc, parsing it for relevant information (trivial with
 CSV, less so for structured data like JSON or XML), and storing it
 in a database. To which you then point SQLAlchemy.

 So you're already doing the fiddly bit just to get stuff into the database.

 The neat filter operations you cite are actually done by special
 methods on the objects representing tables and columns. For example,

   User.name == None

 is done via the __eq__ method of User.name. And they return
 strings: bare SQL. The beauty of this is that one can write almost
 idiomatic python, and SQLA will generate correct SQL in the right
 dialect for the database backend, and with all the values correctly
 escaped.

 However, it does presume you _already_ have a backend that can be
 queried with SQL.

  Also, is this a valid way to use an ORM suite?

 Well, in principle sure. But SQLA won't do it for you directly. It really
 is for data already stored in an SQL queriable database.

 Your point about using SQLA's filter operations is right, _provided_
 you have already loaded the original data into a database with the
 right schema. If you've done that work, then SQLA may well serve
 you well from that point on.

 Cheers,
 --
 Cameron Simpson c...@zip.com.au

 We knew Army cadets were involved because they cut through two fences
 to get to the goats, and 15 feet away there was an unlocked gate.
 - a director of sports information in the Navy, regarding the theft
   of some mascots from the Naval Academy by Army rivals
 --
 https://mail.python.org/mailman/listinfo/python-list




-- 
--- Get your facts first, then you can distort them as you please.--
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mapping objects

2014-02-02 Thread Cameron Simpson
On 02Feb2014 07:41, Rita rmorgan...@gmail.com wrote:
 Thanks for the response Cameron. No amount of 'googling' could provide me
 with that caliber response :-)
 
 So, it seems regardless I would need a database.

To use SQLA, yes.

The SQLite backend is a very cheap/easy way to start; local files,
no server needed etc.

In unit tests I use this DB URL: 'sqlite:///:memory:'. It makes an
in-memory database. Of course, it vanishes as soon the the program
exits, but for this purpose that's fine.

BTW, if you're parsing XML data specificly, look at BeautifulSoup
4 and XPath (search syntax; IIRC the XML objects you get from BS4
can use it to locate things).

Cheers,
-- 
Cameron Simpson c...@zip.com.au

The nice thing about standards is that you have so many to choose from;
furthermore, if you do not like any of them, you can just wait for next
year's model.   - Andrew S. Tanenbaum
-- 
https://mail.python.org/mailman/listinfo/python-list


mapping objects

2014-02-01 Thread Rita
Hello,

I want to learn more about ORMs so I stumbled upon, SqlAlchemy.

If i had a JSON document (or XML, CSV, etc.._) is it possible to convert it
to a SQLAlchemy objects? I like the ability to query/filter (
http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#common-filter-operators)
 the
data assuming I set up the proper schema.

Also, is this a valid way to use an ORM suite?





-- 
--- Get your facts first, then you can distort them as you please.--
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mapping objects

2014-02-01 Thread Cameron Simpson
On 01Feb2014 20:46, Rita rmorgan...@gmail.com wrote:
 I want to learn more about ORMs so I stumbled upon, SqlAlchemy.
 
 If i had a JSON document (or XML, CSV, etc.._) is it possible to convert it
 to a SQLAlchemy objects? I like the ability to query/filter (
 http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#common-filter-operators)
  the
 data assuming I set up the proper schema.

Well, not as directly as you might hope. As I recall, SQLAlchemy
ORMs provide an easy way to make objects representing database
entities and whose methods automatically drive the necessary SQL
actions to manipulate them.

On that basis, you won't get anywhere without loading up the
JSON/XML/etc, parsing it for relevant information (trivial with
CSV, less so for structured data like JSON or XML), and storing it
in a database. To which you then point SQLAlchemy.

So you're already doing the fiddly bit just to get stuff into the database.

The neat filter operations you cite are actually done by special
methods on the objects representing tables and columns. For example,

  User.name == None

is done via the __eq__ method of User.name. And they return
strings: bare SQL. The beauty of this is that one can write almost
idiomatic python, and SQLA will generate correct SQL in the right
dialect for the database backend, and with all the values correctly
escaped.

However, it does presume you _already_ have a backend that can be
queried with SQL.

 Also, is this a valid way to use an ORM suite?

Well, in principle sure. But SQLA won't do it for you directly. It really
is for data already stored in an SQL queriable database.

Your point about using SQLA's filter operations is right, _provided_
you have already loaded the original data into a database with the
right schema. If you've done that work, then SQLA may well serve
you well from that point on.

Cheers,
-- 
Cameron Simpson c...@zip.com.au

We knew Army cadets were involved because they cut through two fences
to get to the goats, and 15 feet away there was an unlocked gate.
- a director of sports information in the Navy, regarding the theft
  of some mascots from the Naval Academy by Army rivals
-- 
https://mail.python.org/mailman/listinfo/python-list