SQLAlchemy will autodetect your tables and foreign keys
Instead of joins, SQLAlchemy keeps everything in an object-oriented manner: you can simply set up references to foreign tables, and instead of joining all the time, you can (for example) just set up "employees" as a many-to-one relationship with "company" say company.employees and it will return a list for you. You also don't have to call an "insert" function -- you just create a new object instance and commit.
Instead of getting a table object like in webpy, in SQL Alchemy you associate an existing class with a table in the database. This allows you to not only define a lot of methods for dealing with that table, and keep them in the same namespace, but you can also edit the init function so when you create a new row, you can build any logic you need into the class.
SQLAlchemy has more data types, like the PickleType, which allows you to just dump Python data into a blob/binary row. You can also create your own data types, too.
So bottom line is I prefer SQLAlchemy's abstraction over this, and it's just a more robust system, and better at doing its job.
That said, I'm not saying that this is a waste or anything. It's probably a lot simpler to get started than dealing with SQL Alchemy -- there is a decent amount of overhead setting everything up.
web2py does not auto-detect tables. The problem is that, like SQLAlchemy, it has more data-types than SQL, and as SQLALchemy, you can define your own (like a pickle-type if you like). Auto detection and custom data-types cannot work together. For mysql and postgresql we have script that autodetect tables and generate web2py models.
In web2py you do not have to "join all the time". You can also use recursive selects and it works like in sqlalchemy.
In web2py have to call an "insert" function because, by design it is not an ORM, it is a database abstraction layer. We feel forcing a relational model into an object model is sometimes too much of a stretch. We do not wish to hide the underlying relational model: web2py has functions like insert, update, delete, and select which map 1-to-1 into the corresponding SQL. Moreover our tests indicate that the logic to run a database abstraction layer into an object relational mapper involve metaclass programming and that introduces a considerable slow down. web2py is faster, small and easier to read then sqlalchemy because of this.
web2y supports computed fields and virtual fields. Syntactically this is different from defining methods in SQLAlchemy but functionally it is the same.
Even if web2py is not an ORM, more than one year ago, as a proof of concept, we implemented both the Django ORM and the SQLALchemy ORM on top of the web2py DAL. This allows you to define some tables, using Django syntax, some using web2py syntax, and some using SQLAlchemy syntax in the same program. Nobody showed an interest in this functionality so we did not spend extra time on it.
Auto detection and custom data-types cannot work together.
That's the thing; SQL Alchemy can handle both by allowing the user to autoload the table if necessary. If web2py has a function for autodetecting tables, that's almost the same thing. However, this isn't really shown in the link.
In web2py you do not have to "join all the time". You can also use recursive selects and it works like in sqlalchemy.
SQLAlchemy allows you to specify relations to other tables and will automatically populate those relations with a list if appropriate. How does it work in web2py? I think it would help users evaluate your tool if you included some joining examples -- joins are pretty much the point of relational databases!
We feel forcing a relational model into an object model is sometimes too much of a stretch.
Fair enough! Like other people have said, it would certainly be useful where you don't need all of SQLAlchemy's features and preferred to do things much more simply. SQLA does have a lot of boilerplate to work through. This is a design choice, not a flaw, and I am just preferable to the way SQLA works.
I love web2py and I'm using it in the (huge) project I'm working on now. I just prefer to plug in SQL Alchemy to handle DB stuff.
Also, I have a completely unrelated web2py question: while you guys were working on adding session capability, you published an API of how sessions were going to work. IIRC, it completely changed when you eventually did add session capability. Why was this?
We only provide these two files 12 that extract a mysql or pgsql table and write a dal model. It is not as good as sqlalchemy because we have not been much concerned with legacy tables. We will improve this anyhow.
web2py handles joins a relations to the extend the underlying database does. Suppose you have
where dog.owner is a reference to a person. You can do a INNER JOIN
for row in db(Person.id==Dog.owner).select(): print row.person.name, row.dog.name
a LEFT OUTER JOIN
for row in db().select(Person.ALL,Dog.ALL,left=Dog.on(Person.id==Dog.owner)): print row.person.name, row.dog.name
or you can fetch a dog and find his owner
print Dog(name="Skipper").owner.name
or you can fetch a person and find his dogs
for dog in Person(name="John").dog.select(): print dog.name
I am not sure what you are talking about session capability. Web2py had session support since the first public version in Oct 2007 and we never changed it.
It's just a suggestion. Someone like me who's just browsing to see what kind of features it offers will look at the list provided and come to the conclusion (as I did) that those features aren't offered.
-1
u/mdipierro Dec 09 '10
why?