DBIx::SimpleQuery - Query databases using as little code as possible


NAME

DBIx::SimpleQuery - Query databases using as little code as possible


SYNOPSIS

  use DBIx::SimpleQuery;
  
  DBIx::SimpleQuery::set_defaults(
      "dsn"      => "DBI:Pg:test_database",
      "user"     => "test_user",
      "password" => "test_password",
  );
  
  sub get_name {
      my $user_id = qs(shift());
      return query "SELECT name FROM users WHERE user_id = $user_id";
  }
  
  print get_name("mo'connor") . "\n";
  
  
  foreach my $name (query "SELECT name FROM users ORDER BY name") {
      print $name . "\n";
  }
  
  foreach my $row (query "SELECT user_id, name FROM users") {
      print $row->{"user_id"} . "\t" . $row->{"name"} . "\n";
  }


DESCRIPTION

DBIx::SimpleQuery is designed for anyone who wants to run specific SQL commands against a database with as little surrounding structure as possible.

It exports two functions, query and qs (quote-string), which allow you to include SQL in your code without needing to deal with database handlers, DSNs, and the like.

qs() escapes a string and surrounds it with single quotes, so that it can be safely embedded in a query. Whenever possible, it uses the appropriate DBD module to do this.

query() runs one or more queries against a database, and returns a value or a structure that can be evaluated in a number of ways, depending on your need.

Multi-word functions may be called either in function_name or functionName form, as per your preference.

Methods


AUTHOR

Steve Simms (ssimms@cpan.org)


COPYRIGHT

Copyright 2004 Steve Simms. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


SEE ALSO

DBI DBIx::SimpleQuery::Object

 DBIx::SimpleQuery - Query databases using as little code as possible