前言介紹
- 這款 WordPress 外掛「NinjaDB」是 2017-09-25 上架。
- 目前尚無安裝啟用數,是個很新的外掛。如有要安裝使用,建議多測試確保功能沒問題!
- 上一次更新是 2017-09-26,距離現在已有 2776 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 4.0 以上版本才可以安裝。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
techjewel | adreastrian |
內容簡介
一個輕量級、具有表達能力的 WordPress 查詢建構器。NinjaDB 使用相同的 $wpdb 實例和方法,它將幫助您輕鬆與表達能力撰寫 $wpdb 查詢。至少需要 PHP 5.3。
它具有一些高級功能,例如:
- 像 Laravel 基本查詢一樣的查詢
- where、orWhere 方法
- 在所有列或特定列中搜索數據
- 輕鬆實現分頁
- 使用 insert、update 或 delete 方法有表達能力。
語法與 Laravel 的查詢建構器非常相似。
簡單查詢:
以下查詢將返回 id = 3 的行,如果沒有行則返回 null。
$row = ninjaDB('my_table')->find(3);
完整查詢:
$query = ninjaDB('my_table')->where('post_author', '=', 1); // for equal you can just use where('post_author, 1);
// Get result as array of objects
$query->get();
完整用法 API
### 初始化
// 選擇資料表
$query = ninjaDB()->table('post'); // post 為不帶前綴的資料表名稱;
或者您可以將資料表名稱作為引數傳遞
// 選擇資料表
$query = ninjaDB('my_table'); // post 為不帶前綴的資料表名稱;
查詢
輕鬆取得
以下查詢將返回 id = 3 的行,如果沒有行則返回 null。
$row = ninjaDB('my_table')->find(3);
像這樣使用 echo $row->name 存取您的行。如果欄位名稱不是 id,則作為第二個參數傳遞欄位名稱 ninjaDB('my_table')->find(3, 'author_id');。
以下查詢將以對象數組的形式返回所有行,其 author_id = 3,如果沒有行則返回 null。
$result = ninjaDB('my_table')->findAll('author_id', 3);
選擇
$query = ninjaDB('my_table')->select('*');
多選擇
->select(array('myfield1', 'myfield2', 'amyfield3'));
使用 select 方法多次 select('a')->select('b') 也會選擇 a 和 b。如果您想進行條件選擇(在 PHP if 中),這可能很有用。
取得全部
返回一個對象數組。
$query = ninjaDB('my_table')->where('author_id', 1);
$result = $query->get();
您可以像這樣循環遍歷:
foreach ($result as $row) {
echo $row->name;
}
取得第一行
$query = ninjaDB('my_table')->where('author_id', 1);
$row = $query->first();
返回第一行,如果沒有記錄則返回 null。使用此方法,您還可以確保記錄是否存在。訪問這些將 echo $row->name。
取得行數、最大值、最小值、平均值、總和
$query = ninjaDB('my_table')->where('author_id', 1);
$count = $query->count();
$max = $query->max('views'); // Where `views` is the column name and all these will return integer / float
$min = $query->min('views');
$avg = $query->avg('views');
$avg = $query->avg('views');
$sum = $query->sum('views');
where
基本語法為 (field name, operator, value),如果只給兩個參數,則假定使用 = 運算子。因此,where('name', 'jewel') 和 where('name', '=', 'jewel') 是相同的。
ninjaDB('my_table')
->where('name', '=', 'jewel')
原文外掛簡介
A lightweight, expressive query builder for WordPress. NInjaDB use the same $wbdp instance and methods, It will help you to write $wpdb queries easily and expressively. At least PHP 5.3 is required.
It has some advanced features like:
– Query Like Laravel Basic Queries
– Where, orWhere methods
– Search data in all the columns or specific columns
– Easily Implement Pagination
– use insert, update or delete methods expressively.
The syntax is quite similar to Laravel’s query builder.
Simple Query:
The query below returns the row where id = 3, null if no rows.
$row = ninjaDB('my_table')->find(3);
Full Queries:
$query = ninjaDB('my_table')->where('post_author', '=', 1); // for equal you can just use where('post_author, 1);
// Get result as array of objects
$query->get();
Full Usage API
### Initiate
// Select a table
$query = ninjaDB()->table('post'); // post is the table name without prefix;
OR You can pass your table name as an argument
// Select a table
$query = ninjaDB('my_table'); // post is the table name without prefix;
Query
Get Easily
The query below returns the (first) row where id = 3, null if no rows.
$row = ninjaDB('my_table')->find(3);
Access your row like, echo $row->name. If your field name is not id then pass the field name as second parameter ninjaDB('my_table')->find(3, 'author_id');.
The query below returns the all rows as array of objects where author_id = 3, null if no rows.
$result = ninjaDB('my_table')->findAll('author_id', 3);
Select
$query = ninjaDB('my_table')->select('*');
Multiple Selects
->select(array('myfield1', 'myfield2', 'amyfield3'));
Using select method multiple times select('a')->select('b') will also select a and b. Can be useful if you want to do conditional selects (within a PHP if).
Get All
Return an array of objects.
$query = ninjaDB('my_table')->where('author_id', 1);
$result = $query->get();
You can loop through it like:
foreach ($result as $row) {
echo $row->name;
}
Get First Row
$query = ninjaDB('my_table')->where('author_id', 1);
$row = $query->first();
Returns the first row, or null if there is no record. Using this method you can also make sure if a record exists. Access these like echo $row->name.
Get Rows Count, MAX, MIN, AVerage, SUM
$query = ninjaDB('my_table')->where('author_id', 1);
$count = $query->count();
$max = $query->max('views'); // Where `views` is the column name and all these will return integer / float
$min = $query->min('views');
$avg = $query->avg('views');
$avg = $query->avg('views');
$sum = $query->sum('views');
Where
Basic syntax is (fieldname, operator, value), if you give two parameters then = operator is assumed. So where('name', 'jewel') and where('name', '=', 'jewel') is the same.
ninjaDB('my_table')
->where('name', '=', 'jewel')
->whereNot('age', '>', 25)
->orWhere('description', 'LIKE', '%query%');
whereIn
ninjaDB('my_table')
->whereIn( 'id', array(1,2,3) )
->get();
Limit and Offset
->limit(30);
->offset(10);
// or you can use aliases
->take(30);
->skip(10);
Order By
->orderBy('id', 'ASC');
Insert
$data = array(
'name' => 'Jewel',
'description' => 'Hello, There'
);
$insertId = ninjaDB('my_table')->insert($data);
insert() method returns the insert id. optionally you can pass $format of your data as `->insert($data, $format);` where `$format` is an array of formats to be mapped to each of the value in $data
Batch Insert
$data = array(
array(
'name' => 'Jewel',
'description' => 'Hello, There'
),
array(
'name' => 'Adre',
'description' => 'Hello, I am Adre Astrian'
),
);
$insertIds = ninjaDB('my_table')->batch_insert($data);
In case of batch insert, it will return an array of insert ids.
Update
$data = array(
'name' => 'Shahjahan Jewel',
'description' => 'Hello, There'
);
ninjaDB('my_table')->where('id', 5)->update($data);
Will update the name field to Shahjahan Jewel and description field to Hello, There where id = 5.
Delete
ninjaDB('my_table')->where('id', '>', 5)->delete();
Will delete all the rows where id is greater than 5.
If you find any typo or extend any functionality then please edit and send a pull request.
TODO
[ ] join()
[x] whereIN()
[ ] whereNotIN()
[ ] whereBetween
[ ] whereNotBetween
[ ] Having
[ ] GroupBy
[x] selectDistinct
If you would like to implement any of the TODO please feel free to do and do a pull request
And, finally, consider to contribute to this plugin here.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「NinjaDB」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
Yoast SEO 》Yoast SEO:#1 WordPress SEO 外掛, 自 2008 年以來,Yoast SEO 幫助全球數百萬個網站在搜尋引擎中排名更高。, Yoast 的使命是為所有人提供 SEO 服務。我們的...。
Elementor Website Builder – More Than Just a Page Builder 》, 全球超過 1000 萬個網站的領先網站建立平台, Elementor 是專為 WordPress 設計的領先網站建立平台,使網站製作者能夠使用直覺式的視覺建立工具建立專業、像...。
Contact Form 7 》Contact Form 7 可以管理多個聯絡表單,並且您可以使用簡單的標記靈活地自訂表單和郵件內容。此表單支援 Ajax 提交、CAPTCHA、Akismet 垃圾郵件過濾等功能。,...。
Classic Editor 》Classic Editor 是由 WordPress 團隊維護的官方外掛程式,可還原之前(也就是「經典」)的 WordPress 編輯器和「編輯文章」畫面,使使用者可以使用延伸這個畫...。
WooCommerce 》p>WooCommerce是全球最受歡迎的開源電子商務解決方案之一,擁有世界上最多的市場份額。, 我們的核心平臺是免費的、靈活的,並擁有全球社區的支持。開源的自由...。
LiteSpeed Cache 》LiteSpeed Cache for WordPress(LSCWP)是一種全方位的網站加速外掛,包括獨家的伺服器層快取和一系列的優化功能。, LSCWP 支援 WordPress Multisite 及大多...。
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More 》f="https://wpforms.com/features/pre-built-form-templates/?utm_source=wprepo&utm_medium=link&utm_campaign=liteplugin" rel="friend nofollow u...。
Akismet Anti-spam: Spam Protection 》Akismet會檢查您的評論和聯繫表單提交,將它們與全球垃圾郵件數據庫進行比對,以防止站點發佈惡意內容。您可以在部落格的“評論”管理畫面中檢查評論垃圾郵件的...。
Wordfence Security – Firewall, Malware Scan, and Login Security 》fective way to manage multiple WordPress sites with Wordfence installed from a single location., Monitor security status across all your sites from...。
Site Kit by Google – Analytics, Search Console, AdSense, Speed 》Site Kit是Google官方的WordPress外掛程式,提供有關人們如何尋找和使用您的網站的洞察。Site Kit是一站式解決方案,可部署、管理並獲取關鍵Google工具的見解...。
All-in-One WP Migration and Backup 》orage providers such as Dropbox, Google Drive, Amazon S3, and more, making it easy for you to securely store and access your website backups at any...。
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin 》WordPress Mail SMTP外掛, 如果您的WordPress網站無法正確發送電子郵件,您並不孤單。超過三百萬個網站使用WP Mail SMTP可靠地發送電子郵件。, 我們的目標是...。
Really Simple Security – Simple and Performant Security (formerly Really Simple SSL) 》le Plugins include Complianz GDPR, Disable Updates Manager, and Really Simple CAPTCHA., , Really Simple SSL是一個外掛,自動配置你的網站最大程度上使...。
Jetpack – WP Security, Backup, Speed, & Growth 》search engines, and grow your traffic with Jetpack. It’s the ultimate toolkit for WordPress professionals and beginners alike., , Customize and des...。
Yoast Duplicate Post 》這個 WordPress 外掛可以讓使用者複製任何類型 (type) 的文章,或將其複製到新的草稿 (draft) 以供進一步編輯。, 使用方法:, , , 在「編輯文章」或「編輯頁...。