File tree 4 files changed +67
-1
lines changed
4 files changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ A DynamoDB based Eloquent model and Query builder for Laravel.
16
16
+ [ Retrieving all models] ( #retrieving-all-models )
17
17
+ [ Retrieving a model] ( #retrieving-a-model )
18
18
+ [ save()] ( #save )
19
+ + [ create()] ( #create )
19
20
+ [ update()] ( #update )
20
21
+ [ delete()] ( #delete )
21
22
+ [ increment() / decrement()] ( #increment--decrement )
@@ -229,12 +230,21 @@ If the model has sort key and `sortKeyDefault` is defined:
229
230
User::find('foo@bar.com'); // Partition key. sortKeyDefault will be used for Sort key.
230
231
```
231
232
233
+ #### create()
234
+
235
+ ``` php
236
+ $user = User::create([
237
+ 'email' => 'foo@bar.com',
238
+ 'type' => 'profile' // Sort key. If we don't specify this, sortKeyDefault will be used.
239
+ ]);
240
+ ```
241
+
232
242
#### save()
233
243
234
244
``` php
235
245
$user = new User([
236
246
'email' => 'foo@bar.com',
237
- 'type' => 'profile' // Sort key. If we don't specify this, sortKeyDefault will be used.
247
+ 'type' => 'profile'
238
248
]);
239
249
240
250
$user->save();
Original file line number Diff line number Diff line change @@ -129,6 +129,20 @@ public static function all($columns = [])
129
129
return static ::scan ($ columns );
130
130
}
131
131
132
+ /**
133
+ * Save a new model and return the instance.
134
+ *
135
+ * @param array $fillables
136
+ * @param array $options
137
+ * @return \Kitar\Dynamodb\Model\Model|$this
138
+ */
139
+ public static function create (array $ fillables = [], array $ options = [])
140
+ {
141
+ $ instance = new static ($ fillables );
142
+ $ instance ->save ($ options );
143
+ return $ instance ;
144
+ }
145
+
132
146
/**
133
147
* Save the model to the database.
134
148
*
Original file line number Diff line number Diff line change @@ -431,6 +431,29 @@ public function it_can_save_new_instance()
431
431
$ user ->save ();
432
432
}
433
433
434
+ /** @test */
435
+ public function it_can_static_create_new_instance ()
436
+ {
437
+ $ params = [
438
+ 'TableName ' => 'User ' ,
439
+ 'Item ' => [
440
+ 'partition ' => [
441
+ 'S ' => 'p '
442
+ ]
443
+ ],
444
+ 'ConditionExpression ' => 'attribute_not_exists(#1) ' ,
445
+ 'ExpressionAttributeNames ' => [
446
+ '#1 ' => 'partition '
447
+ ]
448
+ ];
449
+
450
+ $ connection = $ this ->newConnectionMock ();
451
+ $ connection ->shouldReceive ('putItem ' )->with ($ params );
452
+ $ this ->setConnectionResolver ($ connection );
453
+
454
+ UserD::create (['partition ' => 'p ' ]);
455
+ }
456
+
434
457
/** @test */
435
458
public function it_cannot_save_new_instance_without_required_key ()
436
459
{
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Kitar \Dynamodb \Tests \Model ;
4
+
5
+ use Kitar \Dynamodb \Model \Model ;
6
+ use Illuminate \Auth \Authenticatable ;
7
+ use Illuminate \Contracts \Auth \Authenticatable as AuthenticatableContract ;
8
+
9
+ class UserD extends Model implements AuthenticatableContract
10
+ {
11
+ use Authenticatable;
12
+
13
+ protected $ table = 'User ' ;
14
+ protected $ primaryKey = 'partition ' ;
15
+ protected $ fillable = [
16
+ 'partition '
17
+ ];
18
+ public $ timestamps = false ;
19
+ }
You can’t perform that action at this time.
0 commit comments