Code Monkey home page Code Monkey logo

database's People

Contributors

annavanbiemen avatar baukevdw avatar

Watchers

 avatar  avatar  avatar

database's Issues

Batch insert

Add support for batch inserts on the connection and query builder

/**
 * @param string $table  The table to insert the given records in
 * @param array[] $rows The rows to insert into the table
 */
public function batchInsert(string $table, array $rows): int

Each row should consist of an key-value array where the key should match the column name.
All the rows should contain the same amount of columns.
The order of the columns doesn't matter (the implementation should sort the keys alphabetically ksort).

Count query

Add public function getCount(string $expression = '1'): int; method to the QueryBuilder.

The getCount method should ignore the query type and select expressions and use $expression as COUNT($expression).

/** @var \Neat\Database\Connection $connection */
$userQuery = $connection->select('*')->from('user'); // \Neat\Database\QueryBuilder
$userCount = $userQuery->getCount();                 // 5
$users     = $userQuery->query();                    // \Neat\Database\Result

Make the query builder immutable

Making the query builder immutable makes code safer and allows the user to write cleaner code.

<?php
/** @var \Neat\Database\Connection $db */
$query = new \Neat\Database\Query($db);

$usersQuery         = $query->from('user', 'u');
$totalUsers         = $usersQuery->select('COUNT(1)')->query()->value();
$users              = $usersQuery->select('u.*')->limit(5)->query()->rows();
$activeUsersQuery   = $usersQuery->where(['active' => true]);
$totalActiveUsers   = $activeUsersQuery->select('COUNT(1)')->query()->value();
$activeRoles        = $activeUsersQuery->select('DISTINCT u.role')->query()->values();
$activeUsers        = $activeUsersQuery->select('u.*')->limit(5)->query()->rows();

Making the query builder immutable might break code so we'll need an upgrade path:
1.x release:

  • Introduce QueryBuilderInterface
  • Introduce ImmutableQuery implements QueryBuilderInterface
  • Introduce MutableQuery extends Query implements QueryBuilderInterface
  • Deprecate Query

2.0 release:

  • Query will be immutable
  • ImmutableQuery will extend Query

Indexed results

It would be nice to be able to get results indexed by a specified result column. Something like:

<?php

$users = $db->query('SELECT email, name FROM contacts')->index('email')->values('name');
// $users = [ '[email protected]' => 'John Doe', ...]

Table gateway

The current object repository has two responsibilities, managing entities and managing rows. It would be nice to have it separated and make the object repository only responsible for managing entities. This requires having a separate table class resposible for managing the rows associated with the entity.

The table class should be something like object/classes/Repository.php@94cda41

Query event

It would be nice to be able to hook into an event that fires for each query executed. This would allow for easier debugging, logging and analysis of performance bottlenecks in applications.

The event should fire after the query result is returned and provide the SQL query, number of rows affected and execution time (Δmicrotime(true)) in its parameters.

PDO instance without exceptions enabled results in internal errors

When performing a query that results in an error, PDO will (when exceptions not enabled) return a boolean instead of throwing a PDOException. This results in an internal error when constructing the query result using this boolean.

Instead we should issue an exception, preferably one implemented by the database package. This exception class should allow for easy access to the query that triggered the exception.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.