$collection = (new \TriTan\Database())->table('user');
// don't recommend, instead use the api: @see ttcms_insert_user()
use TriTan\Common\Password\PasswordHash;
use TriTan\Common\Hooks\ActionFilterHook as hook;
$password = ttcms_generate_password();
$user = $collection->insert([
'user_fname' => 'John',
'user_lname' => 'Doe',
'user_email' => 'johndoe@mail.com',
'user_pass' => (new PasswordHash(hook::getInstance()))->{'hash'}($password);
]);
$user = $collection->where('user_email', 'johndoe@mail.com')->first();
$data = $collection->all();
foreach($data as $d) {
echo $d['user_email'];
}
// don't recommend, instead use the api: ttcms_update_user()
$collection->where('user_email', 'johndoe@mail.com')
->update([
'user_fname' => 'Jack',
'user_email' => 'jackdoe@email.com'
]);
// don't recommend, instead use the api: @see ttcms_delete_user()
$collection->where('user_email', 'johndoe@mail.com')->delete();
// Operators can be '=', '<', '<=', '>', '>=', 'in', 'not in', 'between', 'match'.
// select * from post.json where post_author = 3
$postCollection->where('post_author', 3)->get();
// select * from post.json where post_author = 3
$postCollection->where('post_author', 3)->get();
// select * from post.json where post_author = 3 AND post_type[post_posttype] = 'post'
$postCollection->where('post_author', 3)->where('post_type.post_posttype', 'post')->get();
// select * from post.json where post_author = 3 OR post_author = 1
$postCollection->where('post_author', 3)->orWhere('post_author', 1)->get();
// select * from post.json where ('post_author' > 3 OR post_author = 1)
$postCollection->where(function($post) {
return $post['post_author'] > 3 OR $post['post_author'] == 1;
})->get();