Leonard  Paucek

Leonard Paucek

1667214600

Wildfire: Query Builder Wrapper for The Codeigniter Framework

Wildfire

Wildfire is a wrapper for Query Builder Class from the Codeigniter framework. It is also inspired by the Eloquent ORM from Laravel.

Installation

Install Wildfire via Composer:

$ composer require rougin/wildfire

Basic Usage

Preparation

-- Import this script to a SQLite database

CREATE TABLE users (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    name TEXT NOT NULL,
    age INTEGER NOT NULL,
    gender TEXT NOT NULL,
    accepted INTEGER DEFAULT 0
);

INSERT INTO users (name, age, gender) VALUES ('Rougin', 20, 'male');
INSERT INTO users (name, age, gender) VALUES ('Royce', 18, 'male');
INSERT INTO users (name, age, gender) VALUES ('Angel', 19, 'female');
// application/config/config.php

/*
|--------------------------------------------------------------------------
| Composer auto-loading
|--------------------------------------------------------------------------
|
| Enabling this setting will tell CodeIgniter to look for a Composer
| package auto-loader script in application/vendor/autoload.php.
|
|   $config['composer_autoload'] = TRUE;
|
| Or if you have your vendor/ directory located somewhere else, you
| can opt to set a specific path as well:
|
|   $config['composer_autoload'] = '/path/to/vendor/autoload.php';
|
| For more information about Composer, please visit http://getcomposer.org/
|
| Note: This will NOT disable or override the CodeIgniter-specific
|   autoloading (application/config/autoload.php)
*/
$config['composer_autoload'] = TRUE;
// application/models/User.php

class User extends \Rougin\Wildfire\Model
{
}
// application/controllers/Welcome.php

// Loads the database connection 
$this->load->database();

// Enables the inflector helper. It is being used to determine the class or the
// model name to use based from the given table name from the Wildfire.
$this->load->helper('inflector');

// Loads the required model/s
$this->load->model('user');

Using the Wildfire instance with CI_DB_query_builder

// application/controllers/Welcome.php

use Rougin\Wildfire\Wildfire;

// Pass the \CI_DB_query_builder instance
$wildfire = new Wildfire($this->db);

// Can also be called to \CI_DB_query_builder
$wildfire->like('name', 'Royce', 'both');

// Returns an array of User objects
$users = $wildfire->get('users')->result();

Using the Wildfire instance with CI_DB_result

// application/controllers/Welcome.php

use Rougin\Wildfire\Wildfire;

$query = 'SELECT p.* FROM post p';

// Create raw SQL queries here...
$result = $this->db->query($query);

// ...or even the result of $this->db->get()
$result = $this->db->get('users');

// Pass the result as the argument
$wildfire = new Wildfire($result);

// Returns an array of User objects
$users = $wildfire->result('User');

Properties for the Model instance

Casting attributes to native types

// application/models/User.php

class User extends \Rougin\Wildfire\Model
{
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = array('accepted' => 'boolean');
}

Without native casts

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "gender": "male",
    "accepted": "0",
}

With native casts

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "gender": "male",
    "accepted": false,
}

Notice that the value of accepted was changed from string integer ('0') into native boolean (false). If not specified (e.g. age field), all values will be returned as string except the id field (which will be automatically casted as native integer, also if the said column exists) by default.

Hiding attributes for serialization

// application/models/User.php

class User extends \Rougin\Wildfire\Model
{
    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array
     */
    protected $hidden = array('gender');
}

Without hidden attributes

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "gender": "male",
    "accepted": "0",
}

With hidden attributes

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "accepted": "0",
}

The gender field was not included in the result.

Visible attributes for serialization

// application/models/User.php

class User extends \Rougin\Wildfire\Model
{
    /**
     * The attributes that should be visible for serialization.
     *
     * @var array
     */
    protected $visible = array('gender');
}

Without visible attributes

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "gender": "male",
    "accepted": "0",
}

With visible attributes

{
    "gender": "male"
}

In contrast to the hidden attribute, only the gender field was displayed in the result because it was the only field specified the in visible property of the User model.

Migrating to the v0.5.0 release

The new release for v0.5.0 will be having a backward compatibility break (BC break). So some functionalities on the earlier versions might not be working after updating. This was done to increase the maintainability of the project while also adhering to the functionalities for both Codeigniter and Eloquent ORM. It was also introduced to remove code complexity and to simplify arguments on existing methods. To check the documentation for the last release (v0.4.0), kindly click here.

Change the CodeigniterModel class to Model class

Before

class User extends \Rougin\Wildfire\CodeigniterModel
{
}

After

class User extends \Rougin\Wildfire\Model
{
}

When Wildfire is used as a CI_Model, use WildfireTrait instead.

Before

class User extends \Rougin\Wildfire\Wildfire
{
}

After

class User extends \Rougin\Wildfire\Model
{
    use \Rougin\Wildfire\Traits\WildfireTrait;
}

Change the arguments for PaginateTrait::paginate

Before

// PaginateTrait::paginate($perPage, $config = array())
list($result, $links) = $this->user->paginate(5, $config);

After

$total = $this->db->count_all_results('users');

// PaginateTrait::paginate($perPage, $total, $config = array())
list($offset, $links) = $this->user->paginate(5, $total, $config);

The total count must be passed in the second parameter.

Remove Model::countAll

Before

$total = $this->user->countAll();

After

$total = $this->db->count_all_results('users');

This is being used only in PaginateTrait::paginate.

Change the method ValidateTrait::validation_errors to ValidateTrait::errors

Before

ValidateTrait::validation_errors()

After

ValidateTrait::errors()

Change the property ValidateTrait::validation_rules to ValidateTrait::rules

Before

// application/models/User.php

protected $validation_rules = array();

After

// application/models/User.php

protected $rules = array();

Change the arguments for Wildfire::__construct

Before

$query = $this->db->query('SELECT * FROM users');

// Wildfire::__construct($database = null, $query = null)
$wildfire = new Wildfire($this->db, $query);

After

// $this->db->query returns a CI_DB_result class
$query = $this->db->query('SELECT * FROM users');

// Wildfire::__construct($data)
$wildfire = new Wildfire($query);

If the data is a CI_DB_result, it should be passed on the first parameter.

Change the method Wildfire::asDropdown to Wildfire::dropdown

Before

// Wildfire::asDropdown($description = 'description')
$dropdown = $wildfire->asDropdown();

After

// Wildfire::dropdown($column)
$dropdown = $wildfire->dropdown('description');

Also take note that there is no default value in the argument.

Replace $delimiters with $id in Wildfire::find

Before

$delimiters = array('name' => 'Rougin');

// Wildfire::find($table, $delimiters = array())
$users = $wildfire->find('users', $delimiters);

After

$this->db->where('name', (string) 'Rougin');

$users = $wildfire->get('users')->result();

Use only Wildfire::find to return single row data.

// Wildfire::find($table, $id)
$user = $wildfire->find('users', 1);

Remove set_database and set_query methods

Before

use Rougin\Wildfire\Wildfire;

$wildfire = new Wildfire;

$wildfire->set_database($this->db);

$query = $this->db->query('SELECT * FROM users');

$wildfire->set_query($query);

After

use Rougin\Wildfire\Wildfire;

$wildfire = new Wildfire($this->db);

// or

$query = $this->db->query('SELECT * FROM users');

$wildfire = new Wildfire($query);

The Wildfire parameter must be defined with either CI_DB_query_builder ($this->db) or CB_DB_result instances.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Credits


Download Details:

Author: rougin
Source Code: https://github.com/rougin/wildfire

License: MIT license

#codeigniter 

What is GEEK

Buddha Community

Wildfire: Query Builder Wrapper for The Codeigniter Framework

Hire CodeIgniter Developer

Want to create unique, scalable web and app solutions?

At HourlyDeveloper.io, Expert CodeIgniter developer works particularly for you and your project.

You can Hire CodeIgniter Developer with an extensive variety of skill sets together with PHP, MySQL, PHP frameworks such as Laravel, CakePHP, and Zend, CMS, and e-commerce platforms such as WordPress, Drupal, Magento, WooCommerce, Shopify.

Consult with our experts: https://bit.ly/3hUdppScodeIgniter development services

#hire codeigniter developer #codeigniter developer #codeigniter development #codeigniter development company #codeigniter development services #codeigniter

Laravel Vs CodeIgniter (Choosing Best PHP Framework In 2021)

This is image title

Do you want to create an outstanding web application? You would need a flexible and scalable framework in terms of architecture. Laravel and CodeIgniter have gained a lot of popularity in the last few years. Both frameworks can use to create robust and high-performance web apps. Laravel powers around 0.37% of the websites while CodeIgniter holds 0.36% of the market share.

This is image title

Laravel, being a popular open-source PHP framework, is widely used for building websites and web applications. As this framework uses the MVC pattern, it provides comfortable and easy development. One gets complete control over the project over the development of applications as external APIs can be implemented. Laravel’s MVC architecture reuses the application logic to create scalable web apps.

On the other hand, CodeIgniter is an object-oriented, event-driven functional framework that helps to create fully-featured web applications. It considers as one of the best frameworks to develop dynamic websites and web apps. As the users do not need to rely on MVC development patterns, it can be integrated with third-party plugins to add complex features to the web app. CodeIgniter is known for its amazing security.

1. Built-In Modules
Laravel allows web developers to break the project into smaller modules through a bundle. They can re-use the models across different projects and save development costs.CodeIgniter does not support built-in modules and the programmers need to create and maintain multiple modules with the help of Modular Extension.

2. Library Usage
Laravel possesses object-oriented libraries that used to add the right features. Laravel libraries are comparatively easier to use than the ones available for CodeIgniter.

3. REST APIs
Laravel offers RESTful controllers to help the developers create custom REST APIs without writing any additional code. CodeIgniter does not provide such a feature to simplify the development of APIs. CodeIgniter developers may have to write more code as compared to Laravel developers while creating web apps.

4. HTTPS Support
Laravel supports the HTTPS route and helps programmers to make the right decision for creating a specific URL for each HTTPS route. With CodeIgniter development, programmers need to manage URL helpers to enable protection for data transmission.

5. Data Migration
Laravel provides greater support for data migration while CodeIgniter may have limitations and it may be time-consuming to migrate data while using it.database migration
This is image title

6. PHP Version Support
Both Laravel and CodeIgniter frameworks support the latest PHP version i.e. PHP 7.X. The developers and testers may find it easy to build web apps with Laravel as compared to CodeIgniter development.

7. Technical Documentation
When we talk about the technical documentation for both frameworks, CodeIgniter wins the race as it has easy-to-understand documentation. On the other hand, Laravel has tough documentation that may not be easy to understand for all programmers.

Read More

#laravel or codeigniter #laravel vs codeigniter #laravel vs codeigniter performance #php framework laravel vs codeigniter #php laravel vs codeigniter

Ahebwe  Oscar

Ahebwe Oscar

1620185280

How model queries work in Django

How model queries work in Django

Welcome to my blog, hey everyone in this article we are going to be working with queries in Django so for any web app that you build your going to want to write a query so you can retrieve information from your database so in this article I’ll be showing you all the different ways that you can write queries and it should cover about 90% of the cases that you’ll have when you’re writing your code the other 10% depend on your specific use case you may have to get more complicated but for the most part what I cover in this article should be able to help you so let’s start with the model that I have I’ve already created it.

**Read More : **How to make Chatbot in Python.

Read More : Django Admin Full Customization step by step

let’s just get into this diagram that I made so in here:

django queries aboutDescribe each parameter in Django querset

we’re making a simple query for the myModel table so we want to pull out all the information in the database so we have this variable which is gonna hold a return value and we have our myModel models so this is simply the myModel model name so whatever you named your model just make sure you specify that and we’re gonna access the objects attribute once we get that object’s attribute we can simply use the all method and this will return all the information in the database so we’re gonna start with all and then we will go into getting single items filtering that data and go to our command prompt.

Here and we’ll actually start making our queries from here to do this let’s just go ahead and run** Python manage.py shell** and I am in my project file so make sure you’re in there when you start and what this does is it gives us an interactive shell to actually start working with our data so this is a lot like the Python shell but because we did manage.py it allows us to do things a Django way and actually query our database now open up the command prompt and let’s go ahead and start making our first queries.

#django #django model queries #django orm #django queries #django query #model django query #model query #query with django

Hire Codeigniter Developer - Hire CodeIgniter Developers or Programmers

One of the fastest, lightest, reliable, and completely capable frameworks for a business web app development is the Codeigniter framework from PHP. CodeIgniter provides out-of-the-box libraries to perform operations like Sending Emails, Uploading Files, Managing Sessions, etc.

Want to build an excellent web application for your business?

Then WebClues Infotech is the right place where you could find highly skilled and expert CodeIgniter developers for hire. Share us your requirement, Conduct desired candidate interviews, and finally choose the one best suitably, it is that easy with WebClues Infotech.

So what are you waiting for? Get going on the path to business growth with WebClues Infotech

For more inquiry click here: https://www.webcluesinfotech.com/contact-us/

Hire CodeIgniter Developer: https://www.webcluesinfotech.com/hire-codeigniter-developer/

Email: sales@webcluesinfotech.com

#hire codeigniter developers #hire codeigniter development expert #hire codeigniter developers #hire codeigniter developers or programmers #hire an offshore codeigniter development team #codeigniter programmer

Leonard  Paucek

Leonard Paucek

1667214600

Wildfire: Query Builder Wrapper for The Codeigniter Framework

Wildfire

Wildfire is a wrapper for Query Builder Class from the Codeigniter framework. It is also inspired by the Eloquent ORM from Laravel.

Installation

Install Wildfire via Composer:

$ composer require rougin/wildfire

Basic Usage

Preparation

-- Import this script to a SQLite database

CREATE TABLE users (
    id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    name TEXT NOT NULL,
    age INTEGER NOT NULL,
    gender TEXT NOT NULL,
    accepted INTEGER DEFAULT 0
);

INSERT INTO users (name, age, gender) VALUES ('Rougin', 20, 'male');
INSERT INTO users (name, age, gender) VALUES ('Royce', 18, 'male');
INSERT INTO users (name, age, gender) VALUES ('Angel', 19, 'female');
// application/config/config.php

/*
|--------------------------------------------------------------------------
| Composer auto-loading
|--------------------------------------------------------------------------
|
| Enabling this setting will tell CodeIgniter to look for a Composer
| package auto-loader script in application/vendor/autoload.php.
|
|   $config['composer_autoload'] = TRUE;
|
| Or if you have your vendor/ directory located somewhere else, you
| can opt to set a specific path as well:
|
|   $config['composer_autoload'] = '/path/to/vendor/autoload.php';
|
| For more information about Composer, please visit http://getcomposer.org/
|
| Note: This will NOT disable or override the CodeIgniter-specific
|   autoloading (application/config/autoload.php)
*/
$config['composer_autoload'] = TRUE;
// application/models/User.php

class User extends \Rougin\Wildfire\Model
{
}
// application/controllers/Welcome.php

// Loads the database connection 
$this->load->database();

// Enables the inflector helper. It is being used to determine the class or the
// model name to use based from the given table name from the Wildfire.
$this->load->helper('inflector');

// Loads the required model/s
$this->load->model('user');

Using the Wildfire instance with CI_DB_query_builder

// application/controllers/Welcome.php

use Rougin\Wildfire\Wildfire;

// Pass the \CI_DB_query_builder instance
$wildfire = new Wildfire($this->db);

// Can also be called to \CI_DB_query_builder
$wildfire->like('name', 'Royce', 'both');

// Returns an array of User objects
$users = $wildfire->get('users')->result();

Using the Wildfire instance with CI_DB_result

// application/controllers/Welcome.php

use Rougin\Wildfire\Wildfire;

$query = 'SELECT p.* FROM post p';

// Create raw SQL queries here...
$result = $this->db->query($query);

// ...or even the result of $this->db->get()
$result = $this->db->get('users');

// Pass the result as the argument
$wildfire = new Wildfire($result);

// Returns an array of User objects
$users = $wildfire->result('User');

Properties for the Model instance

Casting attributes to native types

// application/models/User.php

class User extends \Rougin\Wildfire\Model
{
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = array('accepted' => 'boolean');
}

Without native casts

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "gender": "male",
    "accepted": "0",
}

With native casts

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "gender": "male",
    "accepted": false,
}

Notice that the value of accepted was changed from string integer ('0') into native boolean (false). If not specified (e.g. age field), all values will be returned as string except the id field (which will be automatically casted as native integer, also if the said column exists) by default.

Hiding attributes for serialization

// application/models/User.php

class User extends \Rougin\Wildfire\Model
{
    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array
     */
    protected $hidden = array('gender');
}

Without hidden attributes

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "gender": "male",
    "accepted": "0",
}

With hidden attributes

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "accepted": "0",
}

The gender field was not included in the result.

Visible attributes for serialization

// application/models/User.php

class User extends \Rougin\Wildfire\Model
{
    /**
     * The attributes that should be visible for serialization.
     *
     * @var array
     */
    protected $visible = array('gender');
}

Without visible attributes

{
    "id": 1,
    "name": "Rougin",
    "age": "20",
    "gender": "male",
    "accepted": "0",
}

With visible attributes

{
    "gender": "male"
}

In contrast to the hidden attribute, only the gender field was displayed in the result because it was the only field specified the in visible property of the User model.

Migrating to the v0.5.0 release

The new release for v0.5.0 will be having a backward compatibility break (BC break). So some functionalities on the earlier versions might not be working after updating. This was done to increase the maintainability of the project while also adhering to the functionalities for both Codeigniter and Eloquent ORM. It was also introduced to remove code complexity and to simplify arguments on existing methods. To check the documentation for the last release (v0.4.0), kindly click here.

Change the CodeigniterModel class to Model class

Before

class User extends \Rougin\Wildfire\CodeigniterModel
{
}

After

class User extends \Rougin\Wildfire\Model
{
}

When Wildfire is used as a CI_Model, use WildfireTrait instead.

Before

class User extends \Rougin\Wildfire\Wildfire
{
}

After

class User extends \Rougin\Wildfire\Model
{
    use \Rougin\Wildfire\Traits\WildfireTrait;
}

Change the arguments for PaginateTrait::paginate

Before

// PaginateTrait::paginate($perPage, $config = array())
list($result, $links) = $this->user->paginate(5, $config);

After

$total = $this->db->count_all_results('users');

// PaginateTrait::paginate($perPage, $total, $config = array())
list($offset, $links) = $this->user->paginate(5, $total, $config);

The total count must be passed in the second parameter.

Remove Model::countAll

Before

$total = $this->user->countAll();

After

$total = $this->db->count_all_results('users');

This is being used only in PaginateTrait::paginate.

Change the method ValidateTrait::validation_errors to ValidateTrait::errors

Before

ValidateTrait::validation_errors()

After

ValidateTrait::errors()

Change the property ValidateTrait::validation_rules to ValidateTrait::rules

Before

// application/models/User.php

protected $validation_rules = array();

After

// application/models/User.php

protected $rules = array();

Change the arguments for Wildfire::__construct

Before

$query = $this->db->query('SELECT * FROM users');

// Wildfire::__construct($database = null, $query = null)
$wildfire = new Wildfire($this->db, $query);

After

// $this->db->query returns a CI_DB_result class
$query = $this->db->query('SELECT * FROM users');

// Wildfire::__construct($data)
$wildfire = new Wildfire($query);

If the data is a CI_DB_result, it should be passed on the first parameter.

Change the method Wildfire::asDropdown to Wildfire::dropdown

Before

// Wildfire::asDropdown($description = 'description')
$dropdown = $wildfire->asDropdown();

After

// Wildfire::dropdown($column)
$dropdown = $wildfire->dropdown('description');

Also take note that there is no default value in the argument.

Replace $delimiters with $id in Wildfire::find

Before

$delimiters = array('name' => 'Rougin');

// Wildfire::find($table, $delimiters = array())
$users = $wildfire->find('users', $delimiters);

After

$this->db->where('name', (string) 'Rougin');

$users = $wildfire->get('users')->result();

Use only Wildfire::find to return single row data.

// Wildfire::find($table, $id)
$user = $wildfire->find('users', 1);

Remove set_database and set_query methods

Before

use Rougin\Wildfire\Wildfire;

$wildfire = new Wildfire;

$wildfire->set_database($this->db);

$query = $this->db->query('SELECT * FROM users');

$wildfire->set_query($query);

After

use Rougin\Wildfire\Wildfire;

$wildfire = new Wildfire($this->db);

// or

$query = $this->db->query('SELECT * FROM users');

$wildfire = new Wildfire($query);

The Wildfire parameter must be defined with either CI_DB_query_builder ($this->db) or CB_DB_result instances.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Credits


Download Details:

Author: rougin
Source Code: https://github.com/rougin/wildfire

License: MIT license

#codeigniter