chatbox / tmp-data
临时数据提供者
dev-master
2015-01-22 00:12 UTC
Requires
- php: >=5.4
- illuminate/database: ~4.2.12
This package is not auto-updated.
Last update: 2024-09-28 16:51:48 UTC
README
处理临时KVS形式数据时的实用工具
用法
$tmpData = new \TmpData\TempDataProvider([
"tableName" => "tmp_token",
"dns" => "mysql://hogehoge"
]);
$tmpData->set($key,$value); // write data
$token = $tmpData->pickUp($key); //read data and update timestamp
$token = $tmpData->read($key); //just read data
//token will be null or \Chatbox\TempData Object
if($token->isUsable()){ // check if token in term
$key = $token->key;
$value = $token->value;
$createdAt = $token->createdAt;
$updatedAt = $token->updatedAt;
$expiredAt = $token->expiredAt;
$accessedAt = $token->accessedAt;
$deletedAt = $token->deletedAt;
}
$token->update($value); // update data
$token->delete(); // soft delete
$tmpData->flush(); // delete all data
模式
key 字符串 value 字符串 createdAt 时间戳 updatedAt 时间戳 accessedAt 时间戳 expiredAt 时间戳 deletedAt 时间戳
您可以使用 \Chatbox\TmpData\SchemaBuilder
生成 Builder 闭包
# in laravel4
Schema::create('tmp_token', new \Chatbox\TmpData\SchemaBuilder());
Schema::create('tmp_confirm_mail', new \Chatbox\TmpData\SchemaBuilder([
"useAccessedAt" => false,
"defaultExpiredAt" => "200000",
]));
[ "cb_room" => function(Blueprint $table){ $table->unsignedInteger("id",true); $table->string("srug"); $table->unsignedInteger("tenants"); $table->text("prop"); $table->dateTime("created_at"); $table->dateTime("updated_at"); }, "cb_room_tag" => function(Blueprint $table){ $table->unsignedInteger("id",true); $table->unsignedInteger("room_id"); $table->string("type"); $table->string("value"); $table->dateTime("created_at"); $table->dateTime("updated_at"); }, "cb_user" => function(Blueprint $table){ $table->unsignedInteger("id",true); $table->string("name"); $table->string("enter_key"); $table->text("prop"); $table->dateTime("created_at"); $table->dateTime("updated_at"); }, "cb_user_tag" => function(Blueprint $table){ $table->unsignedInteger("id",true); $table->unsignedInteger("user_id"); $table->string("type"); $table->string("value"); $table->dateTime("created_at"); $table->dateTime("updated_at"); }, "cb_tenants" => function(Blueprint $table){ $table->unsignedInteger("id",true); $table->unsignedInteger("room_id"); $table->unsignedInteger("user_id"); $table->boolean("is_kicked"); $table->dateTime("created_at"); $table->dateTime("updated_at"); }, "cb_message" => function(Blueprint $table){ $table->unsignedInteger("id",true); $table->unsignedInteger("room_id"); $table->unsignedInteger("user_id"); $table->string("type"); $table->text("message"); $table->dateTime("created_at"); $table->dateTime("updated_at"); }, ], "seeds" => [ ["master_user",function(Builder $builder){ $builder->insert([ "name"=>"Tom", "sex" => "1" ]); }], ], "include" => [ "user" => __DIR__."/data/user.php" ] ];