Skip to content
kintone query builder php
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src @return self -> @return $this May 9, 2019

kintone query builder php


PHP Version Latest Stable Version Latest Unstable Version License


Query builder for Kintone REST API in PHP. Kintone query builder helps you to make a parameter string query of GET /records.json.



composer require toyokumo/kintone-query-builder:v1.0.0
composer install


use KintoneQueryBuilder\KintoneQueryBuilder;
use KintoneQueryBuilder\KintoneQueryExpr;
// example
// all operators(=, !=, like, not like, <, >, <=, >=, in, not in) are supported
(new KintoneQueryBuilder())->where('name', '=', 'hoge')->build();
// => 'name = "hoge"'
(new KintoneQueryBuilder())
    ->where('favorite', 'in', ['apple', 'banana', 'orange'])
// => 'favorite in ("apple","banana","orange")'
(new KintoneQueryBuilder())
    ->where('age', '>', 10)
    ->andWhere('name', 'like', 'banana') // you can write 'where' instead here (where = andWhere).
    ->andWhere('name', '!=', 'banana')
// => 'age > 10 and name like "banana" and name != "banana"'
(new KintoneQueryBuilder())
    ->where('age', '>', 20)
    ->orderBy('$id', 'desc')
// => 'age > 20 order by $id desc limit 50'
(new KintoneQueryBuilder()) // for nested query, pass KintoneQueryExpr to $builder->where.
    (new KintoneQueryExpr())
        ->where('a', '<', 1)
        ->andWhere('b', '<', 1)
    (new KintoneQueryExpr())
        ->where('c', '<', 1)
        ->andWhere('d', '<', 1)
// => '(a < 1 and b < 1) or (c < 1 and d < 1)'
(new KintoneQueryBuilder())->where('x', '=','ho"ge')->build()
// escape double quote
// => 'x = "ho\"ge"'

example: fetch all records from kintone API

You can't get more than 501 records because of kintone API restriction. In that situation, kintone query builder is very useful.

use KintoneQueryBuilder\KintoneQueryBuilder;
$builder = (new KintoneQueryBuilder())->where(...);
$records = $api->fetch($;
$offset = 0;
$records_max = 500; // max records you can get at once (kintone API restriction)
while(!\empty($records)) {
    // do something
    $records = $api->fetch($builder->offset($offset)->build());

Precautions: methods are mutable methods

Note that $builder->where(...) modifies $builder and returns itself instead of returning a new copied builder object. This may cause unexpected behaivor like this.

$builder = (new KintoneQueryBuilder());
$q0 = $builder->where('x', '=', 1)->build();
// $q0 = 'x = 1'
$q1 = $builder->where('y', '=', 1)->bulid();
// $q1 = 'x = 1 and y = 1', not 'y = 1'

If you want $builder to return 'y=1', you should define a factory function (or a factory class).

function getBaseBuilder() {
    return (new KintoneQueryBuilder())->where('x', '=', 1);
$q0 = getBaseBuilder()->build();
$q1 = getBaseBuilder()->where('y', '=', 1)->build();
$q2 = getBaseBuilder()->bulid(); // you can get 'x = 1' again

This pattern is useful if you want to use the same builder again to build a little bit different query.

More examples.

how to contribute

Feel free to send us pull requests.


git clone
composer install
composer test


Install prettier and run composer format.



You can’t perform that action at this time.