|
List Info
Thread: Simpledb binding
|
|
| Simpledb binding |
  United States |
2007-06-05 07:29:43 |
Hi All,
There have been a few occasions where I've wanted a quick
and easy way
to access a single database table as part of an SCA
component
implementation. I'm just adding the finishing touches (at
least to
the point where it might do something useful) to a binding
called
simpledb. This gives you a CRUD (create, retrieve, update
and delete)
service interface over a database table. It's a bit Active
Record
like, but more simplistic. Here's how it is used...
The code below shows how to do CRUD against a table called
'contact'.
<?php
require 'SCA/SCA.php';
$dbservice = SCA::getService('contact', 'simpledb',
array('config' => 'config/
mysql_config.ini'));
$contact = $dbservice->createDataObject('http://example.org',
'contact');
$contact->shortname = 'bertie';
$contact->fullname = 'Bertie Example';
$contact->email = 'bertie example.org';
$id = $dbservice->create($contact);
echo "Created: $id";
$contact = $dbservice->retrieve('bertie');
echo "Retrieved: " . $contact->fullname;
$contact->fullname = 'Bertie B Example';
$dbservice->update($contact->shortname, $contact);
$dbservice->delete($contact->shortname);
?>
The ini file can contain the following:
dsn = "mysql:host=localhost;dbname=email"
namespace = "http://example.org"
username =xxx
password = xxx
use_lower_case = 1
All but the dsn are optional. The namespace becomes the
namespace of
any SDOs created for the table. The use_lower_case value
lets you
configure how the SDO property names will appear (The
property names
are derived directly from the live database so don't have to
be
specified). If set to false, then what the database uses
will be used
for the SDO properties (e.g. DB2 will be uppercase).
An SCA reference example would look something like:
/**
* The database service
*
* reference
* binding.simpledb contact
*
* config mysql_config.ini
*/
public $dbservice;
I'd be interested in any feedback, thoughts on how this
might be
extended, and so on. My hope is this could be used to
simplify
creating Web services backed by a database (it is a better
fit than
the SDO relational DAS). I think we could also add
optimistic
concurrency quite easily, but using an identifier tag
generated by the
binding, rather than SDO change summaries.
If folks are happy with this, then I'll check it into DUNLIN
once I've
got the main capabilities up and running.
Regards, Graham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "phpsoa" group.
To post to this group, send email to phpsoa googlegroups.com
To unsubscribe from this group, send email to
phpsoa-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.co.uk/group/phpsoa?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Simpledb binding |
  United Kingdom |
2007-06-05 07:39:29 |
Graham Charters wrote:
>
> There have been a few occasions where I've wanted a
quick and easy way
> to access a single database table as part of an SCA
component
> implementation. I'm just adding the finishing touches
(at least to
> the point where it might do something useful) to a
binding called
> simpledb. This gives you a CRUD (create, retrieve,
update and delete)
> service interface over a database table. It's a bit
Active Record
> like, but more simplistic.
Sounds interesting. So, this works with just a single table,
with the
ORM being a 1-1 correspondence between columns and
properties? And does
it depend on PDO, or ..? (Or I could just wait for the code
).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "phpsoa" group.
To post to this group, send email to phpsoa googlegroups.com
To unsubscribe from this group, send email to
phpsoa-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.co.uk/group/phpsoa?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Simpledb binding |
  United States |
2007-06-05 10:51:47 |
On 5 Jun, 13:39, Caroline Maynard <c... php.net> wrote:
> Graham Charters wrote:
>
> > There have been a few occasions where I've wanted
a quick and easy way
> > to access a single database table as part of an
SCA component
> > implementation. I'm just adding the finishing
touches (at least to
> > the point where it might do something useful) to a
binding called
> > simpledb. This gives you a CRUD (create,
retrieve, update and delete)
> > service interface over a database table. It's a
bit Active Record
> > like, but more simplistic.
>
> Sounds interesting. So, this works with just a single
table, with the
> ORM being a 1-1 correspondence between columns and
properties? And does
> it depend on PDO, or ..? (Or I could just wait for the
code ).
Yes, your summary of the ORM is correct. And, yes, it
depends on
PDO. It's been written to support MySQL and DB2 (need to
test I
haven't broken this with my latest changes). It's not
particularly
well factored at the moment for adding support for other
databases :-
( .
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "phpsoa" group.
To post to this group, send email to phpsoa googlegroups.com
To unsubscribe from this group, send email to
phpsoa-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.co.uk/group/phpsoa?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Simpledb binding |
  United States |
2007-06-12 06:23:04 |
I've just committed the code to DUNLIN for simpledb, along
which some
DB2 and MySql 'contact' examples.
The TODO list is:
- unit tests
- documentation
- fix problem with id returned on MySql create being the
row number
rather than the primary key (not worked out how to do this
yet).
- could do with a refactor to separate out the database
differences
into separate components.
- would be nice to have optimistic concurrency.
I've updated MakePackage.php to exclude simpledb from the
next release
(for reasons which should be clear from the above list ).
Design change since original post. Instead of
use_lower_case in the
ini file, you can state case = "xxx" , where xxx
is one of "upper",
"lower" or "mixed". Mixed just makes
the first letter of each
property a capital and the rest lowercase.
Graham.
On 5 Jun, 16:51, Graham Charters <gchart... googlemail.com> wrote:
> On 5 Jun, 13:39, Caroline Maynard <c... php.net> wrote:
>
> > Graham Charters wrote:
>
> > > There have been a few occasions where I've
wanted a quick and easy way
> > > to access a single database table as part of
an SCA component
> > > implementation. I'm just adding the
finishing touches (at least to
> > > the point where it might do something useful)
to a binding called
> > > simpledb. This gives you a CRUD (create,
retrieve, update and delete)
> > > service interface over a database table.
It's a bit Active Record
> > > like, but more simplistic.
>
> > Sounds interesting. So, this works with just a
single table, with the
> > ORM being a 1-1 correspondence between columns and
properties? And does
> > it depend on PDO, or ..? (Or I could just wait for
the code ).
>
> Yes, your summary of the ORM is correct. And, yes, it
depends on
> PDO. It's been written to support MySQL and DB2 (need
to test I
> haven't broken this with my latest changes). It's not
particularly
> well factored at the moment for adding support for
other databases :-
> ( .
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "phpsoa" group.
To post to this group, send email to phpsoa googlegroups.com
To unsubscribe from this group, send email to
phpsoa-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.co.uk/group/phpsoa?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-4]
|
|