At 5:31 PM -0700 9/2/06, David E. Wheeler wrote: >On Sep 2, 2006, at 13:53, Matt S Trout wrote: > >> DWIM AST -> explicit AST -> SQL > >Agreed. This way, the AST does not have to be specific to any one >back end (PostgreSQL, SQLite, MySQL, LDAP, a object iterator, etc.). > >This is also what I was thinking, as I've been trying to work out a >DWIM query mini language that's just Perl and lexes itself into an >AST that can then be passed to some other module to actually do >something with.
From my experience with working on Set::Relation and the Rosetta DBMS (and the now defunct SQL::Routine), if you *really* want to have an explicit AST that says exactly what you mean, is expressive enough for 99+% of any real-world uses, and is very portable, you essentially have to define a whole turing complete language, including the basics (which is what I am doing). It also helps to, on one hand, abstract away any differences in the syntax for invoking built-in operators (eg, '=', 'AND', 'LIKE') and user-defined operators (stored functions / procedures), so that syntax-wise, user-defined operators are simply extensions to the language. But at the same time, it is very useful to have the concept of name-spaces (loosely analagous to SQL schemas and/or packages). Have a pre-defined namespace for built-ins, eg, System::, and another for user-defined functions, eg, User::, and use these everywhere in the AST. Then almost all things in the AST are simply expressions involving function calls, each of which takes zero or more arguments and returns a value. All parts of a SELECT statement can also be composed in this format. I suggest making the arguments named as well, so they are better self-documenting. Note that the names you use in the built-ins under System:: don't have to look the same as the SQL analogs, especially when different DBMSs aren't the same as each other in those regards. You'll also want to explicitly define a type system, and you'll want at least the Boolean type. I'll write more on this later if it is helpful. -- Darren Duncan _______________________________________________ List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class Wiki: http://dbix-class.shadowcatsystems.co.uk/ IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/ Searchable Archive: http://www.mail-archive.com/[email protected]/
