Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

Similar things

  • relations update
  • Relation modules
  • Relations battle plan
  • Relations Battle Plan II and first results
  • Relations, declarative knowledge and inference
  • minor improvements
  • Relations and their domain structures
  • Relations, SQL, views, algebra or how to cook that broth
  • Once again relations, or the need to focus on smaller parts of the big picture. A rant.
  • An initial phase runner for drupal install

Home » blogs » vlado's blog

Relations API - query generation and TODO

Submitted by vlado on Mon, 2005-11-21 08:26.code | drupal | projects | relations | work in progress

OK, I was talking, talking, writing, fuming - here is some code. Please comment. I need some feedback. I need help as well - to make this better. The file is attached to this post.

Some explanation is probably needed, or I might end up scoring even higher mad hatter points. My previous scribbles on relations give background on my thoughts on this. So I won't be repeating them. The goal is to produce an api, which can be used to form predicates, essentially queries on various related things. One and the same relation can be used in many ways. For example in a simple triple - (subject,predicate,object) or (left,relation,right), we can have four different questions - the free variables being subject and object. Things get more complicated when you consider relation tuples with a length more than two. This is the main reason to try and create a query generator.

Now some implementation details. The RFS() function. The parameter passing is a bit awkward. It is not elegant, but I had to solve a particular problem there. Consider that the arguments can be generated using a different RFS function. Consider as well that $arg1 and $arg2 can be generated separately or as part of a single expression. There is a need to pass the arguments (signatures essentially) by name, so we can identify them properly, but the order is not guaranteed or even worse, the order and the number of arguments, as well as their shape can't be known in advance. This leads to what I consider a not elegant, but workable solution. I would love to streamline that.

Probably I need to define somewhat the terminology used in the code:

signature
defines the shape of the relation
used in the query generation
arguments
it does what it says on the box
parameter
synonym for an argument, used in signatures

implementation checklist

Some of the items need to be implemented, some will be implemented at a later stage, thus they are not considered too important, but merely a convenience or sugar.

  • relation api
    • relation signatures (fields, tables, aliases, conditions, parameters)
    • relation sql select statements
    • relation argument filters
    • relation argument functions - like COUNT, DISTINCT, ...
      should it be folded into the signatures?
    • SQL qroups, order
    • todo later
      • automatically determine the signature of a node type
      • relation joins (as in left, right, inner, outer
      • insert,update and delete SQL statements based on relations
      • other sql 'filters' LIKE
  • relation types
    • comment: any node-type with $NodeType.'_signature function is a relation type
    • comment: a node extended via the relation_nodeapi is a relation
    • comment: basic relation implementations
    • node
    • node_revision
    • user
    • node_user
    • todo: node_term
  • predicates
    • predicate implementation # done, via signature['param'], maybe some sugar is needed
    • todo: nodeapi predicates
  • SQL caching
    • todo: cache relation and predicate SQL statements
  • indexes, indexing schemes, and related predicates
    • todo: hierarchies
  • UI todo
    • relation add(select)/remove
    • automatic form generation for relations and related stuff

You will find some usage examples in the quick tests at the end of the code, some of those are pretty dirty shortcuts, but you can see the picture.
related links and discussions

AttachmentSize
rel.inc.txt7.68 KB
vlado's blog | add new comment
Home » blogs » vlado's blog

dikini.net

spreading confusion by accident since 1970