GithubHelp home page GithubHelp logo

maimai-swap / kettle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from inouet/kettle

0.0 2.0 0.0 124 KB

Kettle is a lightweight object-dynamodb mapper for PHP5.

License: MIT License

PHP 100.00%

kettle's Introduction

Kettle

Kettle is a lightweight object-dynamodb mapper for PHP5. Kettle provides a simple interface to Amazon DynamoDB.

See Some Code

<?php
use Kettle\ORM;

$user = ORM::factory('User')->findOne(10);
$user->name = 'John';
$user->save();


$tweets = ORM::factory('Tweet')->where('user_id', 10)
                 ->findMany();

foreach ($tweets as $tweet) {
    echo $tweet->text . PHP_EOL;
}
  1. Configuration

<?php
use Kettle\ORM;

ORM::configure("key",    'AWS_KEY');
ORM::configure("secret", 'AWS_SECRET');
ORM::configure("region", 'AWS_REGION');
  1. Create Model Class

<?php

class User extends ORM {
    protected $_table_name = 'user';
    protected $_hash_key   = 'user_id';
    protected $_schema = array(
      'user_id'    => 'N',  // user_id is number
      'name'       => 'S',  // name is string
      'age'        => 'N',
      'country'    => 'S',
     );
}
  1. Create

<?php

$user = ORM::factory('User')->create();
$user->id = 1;
$user->name = 'John';
$user->age  = 20;
$user->save();
  1. Retrieve

<?php

$user = ORM::factory('User')->findOne(1);
echo $user->name. PHP_EOL;

print_r($user->asArray());
  1. Update

<?php

$user = ORM::factory('User')->findOne(1);
$user->age = 21;
$user->save();
  1. Delete

<?php

$user = ORM::factory('User')->findOne(1);
$user->delete();
  1. Find

<?php

$tweets = ORM::factory('Tweets')
        ->where('user_id', 1)
        ->where('timestamp', '>', 1397264554)
        ->findMany();

foreach ($tweets as $tweet) {
     echo $tweet->text . PHP_EOL;
}
  1. Find by Global Secondary Index

<?php

$users = ORM::factory('User')
        ->where('country', 'Japan')
        ->where('age', '>=', 20)
        ->index('country-age-index')  // specify index name
        ->findMany();
  1. Query Filtering

<?php

$tweets = ORM::factory('Tweets')
          ->where('user_id', 1)
          ->filter('is_deleted', 0) // using filter
          ->findMany();

kettle's People

Contributors

inouet avatar maimai-swap avatar teefax avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.