Development

/plugins/sfAmazonSimpleDBPlugin/trunk/README

You must first sign up to be able to contribute.

root/plugins/sfAmazonSimpleDBPlugin/trunk/README

Revision 6818, 5.1 kB (checked in by nicolas, 1 year ago)

sfAmazonSimpleDBPlugin:

  • Added pagination capabilities
  • Removed unused files provided with the official Amazon SimpleDB PHP library
Line 
1 = sfAmazonSimpleDBPlugin =
2
3 This plugin provide Symfony integration for the
4 [http://www.amazon.com/b/ref=sc_fe_l_2?ie=UTF8&node=342335011&no=3435361&me=A36L942TSJ2AJA Amazon SimpleDB service].
5
6 == Prerequisites ==
7
8 You need to have an access to the Amazon SimpleDB service, and have an access id
9 and an associated private secret key.
10
11 If you don't have an account yet, you can [http://www.amazon.com/b/ref=sc_fe_l_2?ie=UTF8&node=342335011&no=3435361&me=A36L942TSJ2AJA request for it here].
12
13 == Installation ==
14
15 For the moment this plugin is only available from the
16 [http://svn.symfony-project.org/plugins Symfony plugins SVN
17 repository], in an alpha state. Use with caution !
18
19 To install the plugin into your existing project, checkout the source into your
20 {{{plugins}}} directory like this:
21
22 {{{
23 $ cd /path/to/project/root
24 $ svn co http://svn.symfony-project.org/plugins/sfAmazonSimpleDBPlugin/trunk plugins/sfAmazonSimpleDBPlugin
25 $ php symfony cc
26 }}}
27
28 Now configure your identifiers in the {{{app.yml}}} of your application(s),
29 adding these lines :
30
31 {{{
32   sfAmazonSimpleDBPlugin:
33     aws_access_key:         abcdefghijk12345
34     aws_secret_key:         01234567890AbCdEfGhIjKlMnOpQ
35 }}}
36
37 You're done and ready to use the plugin.
38
39 == Usage ==
40
41 Here are some basic operations you can do with the plugin API :
42
43 === Amazon SimpleDB client instanciation ===
44
45 To instanciate the SimpleDB client :
46
47 {{{
48 $service = sfAmazonSimpleDBClient::getInstance();
49 }}}
50
51 === Creating a domain ===
52
53 A domain is something like a database table. Here, to create a domain named
54 {{{Products}}} :
55
56 {{{
57 $domainCreation = $service->createDomain('Products');
58 }}}
59
60 === Listing domains ===
61
62 To list available domains for your AWS account :
63
64 {{{
65 $domainsQuery = $service->listDomains();
66 echo implode(', ', $domainsQuery['results']);
67 }}}
68
69 You can even limit the number of results, eg. for pagination purpose:
70
71 {{{
72 $domainsQuery = $service->listDomains(5);
73 echo '5 first domains : '.implode(', ', $domainsQuery['results']);
74
75 if (isset($domainsQuery['next_token']))
76 {
77   $nextDomainsQuery = $service->listDomains(5, $domainsQuery['next_token']);
78   echo 'Next 5 domains : '.implode(', ', $nextDomainsQuery['results']);
79 }
80 }}}
81
82 === Selecting a domain ===
83
84 To select a domain to do some operation :
85
86 {{{
87 $service->selectDomain('Products');
88 }}}
89
90 Note that you can chain methods, like this :
91
92 {{{
93 $service->selectDomain('Products')->query("['Color' = 'Blue']");
94 }}}
95
96 === Inserting data ===
97
98 To insert some rows in the database, do the following :
99
100 {{{
101 $service->selectDomain('Products');
102 $service->putAttributes('Shirt',    array('Color' => 'Blue', 'Size' => 'Big'));
103 $service->putAttributes('Trousers', array('Color' => 'Red',  'Size' => 'Medium'));
104 }}}
105
106 A nice feature of SimpleDB is to handle multiple attribute values. Eg if we want
107 our Hat product to have both yellow, green and purple colors available :
108
109 {{{
110 $service->putAttributes('Hat', array('Color' => array('Yellow', 'Green', 'Red'),
111                                      'Size'  => 'Small'));
112 }}}
113
114 === Querying the database ===
115
116 The query syntax of SimpleDB is very simple. here's the way to retrieve all
117 small and red products :
118
119 {{{
120 $resultsQuery = $service->query("['Color' = 'Red'] intersection ['Size' = 'Small']");
121 echo 'Red small products are '.implode(', ', $resultsQuery['results']);
122 }}}
123
124 [http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_Query.html#SDB_API_Query_QueryExpressionSyntax More on query syntax and available operators].
125
126 You can even limit the number of results, eg. for pagination purpose:
127
128 {{{
129 $resultsQuery = $service->query("['Color' = 'Red']", 5)
130 echo '5 first results : '.implode(', ', $resultsQuery['results']);
131
132 if (isset($resultsQuery['next_token']))
133 {
134   $nextResultsQuery = $service->query("['Color' = 'Red']", 5, $resultsQuery['next_token']);
135   echo 'Next 5 results : '.implode(', ', $nextResultsQuery['results']);
136 }
137 }}}
138
139 === Attribute replacement (record update) ===
140
141 To update the properties of a product, we can do the following :
142
143 {{{
144 $replacement = $service->putAttributes('Trousers', array('Color' => 'Black',
145                                                          'Size'  => 'Tiny'), true);
146 }}}
147
148 Here all old attributes will be overidden by the new provided ones.
149
150 === Attributes deletion ===
151
152 To reset the value of an attribute for a product, we can do :
153
154 {{{
155 $service->deleteAttributes('Hat', 'Color', 'Red');
156 }}}
157
158 To remove all values for a given attribute name :
159
160 {{{
161 $service->deleteAttributes('Hat', 'Color');
162 }}}
163
164 === Entry deletion ===
165
166 To completely delete an entry (here a product), we must delete all its related
167 attributes :
168
169 {{{
170 $service->deleteAttributes('Hat');
171 }}} 
172
173 === Domain deletion ===
174
175 To recursively delete a domain and all related entries :
176
177 {{{
178 $service->deleteDomain('Products');
179 }}}
180
181 == TODO ==
182
183  * Create a module to administrate Amazon SimpleDB databases
184
185 == Changelog ==
186
187 === 2007-12-29 ===
188
189  * Initial commit
190
191 == Contact and licensing informations ==
192
193 This plugin has been released by [http://prendreuncafe.com Nicolas Perriault]
194 <nperriault AT gmail.com> and is licensed under the
195 [http://en.wikipedia.org/wiki/MIT_License MIT license].
Note: See TracBrowser for help on using the browser.