PHP code example of darkterminal / gitlab-json-db

1. Go to this page and download the library: Download darkterminal/gitlab-json-db library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

darkterminal / gitlab-json-db example snippets



use GitlabDB\GitlabDB;

$options['personal_access_token']    = "YOUR_GITLAB_ACCESS_TOKEN";
$options['project_id']               = "YOUR_GITLAB_PROJECT_ID";
$options['branch']                   = "YOUR_GITLAB_BRANCH";
$options['cloud_url']                = "YOUR_GITLAB_URL";

$path = 'YOUR_PATH_ON_GITLAB';

$json_db = new GitlabDB( $options, $path ); // Or passing the file path of your json files with no trailing slash, default is the root directory. E.g.  new GitlabDB( $options, 'database' )


$json_db->insert( 'users.json',
	[
		'name' => 'Thomas',
		'state' => 'Nigeria',
		'age' => 22
	]
);


$users = $json_db->select( '*' )
	->from( 'users.json' )
	->get();
print_r( $users );


$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->get();
print_r( $users );



$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas' ] )
	->get();
print_r( $users );

// Defaults to Thomas OR Nigeria
$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas', 'state' => 'Nigeria' ] )
	->get();
print_r( $users );

// Now is THOMAS AND Nigeria
$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas', 'state' => 'Nigeria' ], 'AND' )
	->get();
print_r( $users );



$users = $json_db->select( 'name, state' )
	->from( "users" )
	->where( array( "state" => GitlabDB::regex( "/ria/" )), GitlabDB::AND )
	->get();
print_r( $users );
// Outputs are rows which contains "ria" string in "state" column.


$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas' ] )
	->order_by( 'age', GitlabDB::ASC )
	->get();
print_r( $users );


$json_db->update( [ 'name' => 'Oji', 'age' => 10 ] )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas' ] )
	->trigger();



$json_db->delete()
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas' ] )
	->trigger();



$json_db->to_mysql( 'users.json', 'users.sql' );


$json_db->to_mysql( 'users.json', 'users.sql', false );