Skip to content

Commit

Permalink
First useable version
Browse files Browse the repository at this point in the history
  • Loading branch information
iquito committed Jul 26, 2024
0 parents commit 605d3ef
Show file tree
Hide file tree
Showing 78 changed files with 3,108 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]

end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = false

[*.php]

insert_final_newline = true
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/tests export-ignore
/examples export-ignore
/docker export-ignore
/vendor-bin export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/captainhook.json export-ignore
/phpstan.neon export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml export-ignore
/psalm-baseline.xml export-ignore
/ruleset.xml export-ignore
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.idea
/composer.lock
/vendor
/vendor-bin/**/vendor
/vendor-bin/**/composer.lock
/.phpunit.result.cache
/.phpcs-cache
/tests/_output
/tests/_reports
/build
/tools/cache/*
!/tools/cache/.gitkeep
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2024 Andreas Leathley
Copyright (c) 2006-2018 Doctrine Project

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Squirrel Connection
===================

![PHPStan](https://img.shields.io/badge/style-level%20max-success.svg?style=flat-round&label=phpstan) [![Packagist Version](https://img.shields.io/packagist/v/squirrelphp/connection.svg?style=flat-round)](https://packagist.org/packages/squirrelphp/connection) [![PHP Version](https://img.shields.io/packagist/php-v/squirrelphp/connection.svg)](https://packagist.org/packages/squirrelphp/connection) [![Software License](https://img.shields.io/badge/license-MIT-success.svg?style=flat-round)](LICENSE)

Provides a slimmed down concise interface for the low level database connection (ConnectionInterface), as a more simple replacement to Doctrine DBAL and a more streamlined/opinionated interface compared to pure PDO. It supports MySQL, MariaDB, Sqlite and PostgreSQL and is currently based on PDO, although that is considered an implementation detail.

Much code for the exception handling was taken from Doctrine DBAL. This library is currently only internally used in [squirrelphp/queries](https://github.com/squirrelphp/queries) and should not be used on its own, as the API is not yet stable. Use [squirrelphp/queries](https://github.com/squirrelphp/queries) instead or even better, use [squirrelphp/entities](https://github.com/squirrelphp/entities) / [squirrelphp/entities-bundle](https://github.com/squirrelphp/entities-bundle) instead, as those are more high-level and stable.

A stable version of this package will eventually come out, once the API surface has been thought about more and there is more experience using this package within the other SquirrelPHP packages.
48 changes: 48 additions & 0 deletions bin/vendorbin
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env php
<?php
error_reporting(E_ALL); // Report everything, even notices
set_time_limit(0); // No time limit for console commands

$projectDir = dirname(__DIR__);

$composerRunType = $_SERVER['argv'][1] ?? 'outdated';

require $projectDir.'/vendor/autoload.php';

$sourceFinder = new \Symfony\Component\Finder\Finder();
$sourceFinder->in($projectDir . '/vendor-bin')->directories()->depth(0)->sortByName();

/** @var array<string, \Symfony\Component\Process\Process> $tools */
$tools = [];

foreach ($sourceFinder as $directory) {
$toolName = $directory->getFilename();

$options = [
'--ansi',
];

if ($composerRunType === 'update') {
$options[] = '--no-progress';
}

$process = new \Symfony\Component\Process\Process(['composer', $composerRunType, ...$options]);
if (isset($_SERVER['COMPOSER_CACHE_DIR'])) {
$process->setEnv(['COMPOSER_CACHE_DIR' => $_SERVER['COMPOSER_CACHE_DIR']]);
}
$process->setWorkingDirectory($projectDir . '/vendor-bin/' . $toolName);
$process->start();
$process->wait();

echo 'Running composer ' . $composerRunType . ' for ' . $toolName . ' ...' . "\n";

$processOutput = \trim($process->getOutput());

if ($composerRunType === 'update') {
$processOutput = \trim($processOutput . "\n" . $process->getErrorOutput());
}

if (\strlen($processOutput) > 0) {
echo $processOutput . "\n";
}
}
72 changes: 72 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "squirrelphp/connection",
"type": "library",
"description": "Slimmed down concise connection interface for database queries and transactions supporting MySQL, MariaDB, PostgreSQL and SQLite.",
"keywords": [
"php",
"mysql",
"pgsql",
"sqlite",
"database",
"connection",
"abstraction"
],
"homepage": "https://github.com/squirrelphp/connection",
"license": "MIT",
"authors": [
{
"name": "Andreas Leathley",
"email": "[email protected]"
}
],
"require": {
"php": ">=8.2",
"ext-pdo": "*"
},
"require-dev": {
"captainhook/captainhook-phar": "^5.0",
"phpunit/phpunit": "^11.0",
"mockery/mockery": "^1.0",
"squirrelphp/types": "^1.0",
"symfony/finder": "^7.0",
"symfony/process": "^7.0"
},
"suggest": {
"squirrelphp/queries": "Symfony integration of squirrelphp/queries - automatic assembling of decorated connections",
"squirrelphp/queries-bundle": "Symfony integration of squirrelphp/queries - automatic assembling of decorated connections",
"squirrelphp/entities": "Makes defining typed entities possible and easy",
"squirrelphp/entities-bundle": "Automatic integration of squirrelphp/entities in Symfony"
},
"config": {
"sort-packages": false,
"allow-plugins": {
"captainhook/captainhook-phar": true
}
},
"autoload": {
"psr-4": {
"Squirrel\\Connection\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Squirrel\\Connection\\Tests\\": "tests/"
}
},
"scripts": {
"phpstan": "vendor-bin/phpstan/vendor/bin/phpstan analyse --configuration=tools/phpstan.neon",
"phpstan_full": "rm -Rf tools/cache/phpstan && vendor-bin/phpstan/vendor/bin/phpstan analyse --configuration=tools/phpstan.neon",
"phpstan_base": "vendor-bin/phpstan/vendor/bin/phpstan analyse --configuration=tools/phpstan.neon --generate-baseline=tools/phpstan-baseline.php",
"psalm": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --show-info=false",
"psalm_full": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --clear-cache && vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --show-info=false",
"psalm_base": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --set-baseline=tools/psalm-baseline.xml",
"phpunit": "vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --cache-result-file=tools/cache/.phpunit.result.cache --colors=always --testsuite=unit",
"phpunit_clover": "vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --cache-result-file=tools/cache/.phpunit.result.cache --coverage-text --coverage-clover build/logs/clover.xml",
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --coverage-html=tests/_reports",
"phpcs": "vendor-bin/phpcs/vendor/bin/phpcs --standard=tools/ruleset.xml --extensions=php --cache=tools/cache/.phpcs-cache --colors src tests",
"phpcs_diff": "vendor-bin/phpcs/vendor/bin/phpcs -s --standard=tools/ruleset.xml --extensions=php --cache=tools/cache/.phpcs-cache --colors src tests",
"phpcs_fix": "vendor-bin/phpcs/vendor/bin/phpcbf --standard=tools/ruleset.xml --extensions=php --cache=tools/cache/.phpcs-cache --colors src tests",
"binupdate": "bin/vendorbin update",
"binoutdated": "bin/vendorbin outdated"
}
}
9 changes: 9 additions & 0 deletions docker/Dockerfile/mariadb_ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# syntax=docker/dockerfile:1
FROM mariadb:latest

COPY docker/ssl/squirrel.crt /etc/mysql/certs/server.crt
COPY docker/ssl/squirrel.key /etc/mysql/certs/server.key
COPY docker/ssl/DadaismCA.crt /etc/mysql/certs/ca.crt

RUN chmod 600 /etc/mysql/certs/server.key
RUN chown mysql:mysql /etc/mysql/certs/server.key
9 changes: 9 additions & 0 deletions docker/Dockerfile/mysql_ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# syntax=docker/dockerfile:1
FROM mysql/mysql-server:latest

COPY docker/ssl/squirrel.crt /etc/mysql/certs/server.crt
COPY docker/ssl/squirrel.key /etc/mysql/certs/server.key
COPY docker/ssl/DadaismCA.crt /etc/mysql/certs/ca.crt

RUN chmod 600 /etc/mysql/certs/server.key
RUN chown mysql:mysql /etc/mysql/certs/server.key
9 changes: 9 additions & 0 deletions docker/Dockerfile/postgres_ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# syntax=docker/dockerfile:1
FROM postgres:latest

COPY docker/ssl/squirrel.crt /var/lib/postgresql/server.crt
COPY docker/ssl/squirrel.key /var/lib/postgresql/server.key
COPY docker/ssl/DadaismCA.crt /var/lib/postgresql/ca.crt

RUN chmod 600 /var/lib/postgresql/server.key
RUN chown postgres:postgres /var/lib/postgresql/server.key
31 changes: 31 additions & 0 deletions docker/compose/composer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
composer:
image: thecodingmachine/php:8.3-v4-cli
container_name: squirrel_connection_composer
working_dir: /usr/src/app
command: [ "composer", "${COMPOSER_COMMAND}", "--ansi" ]
logging:
driver: "none"
volumes:
- ./.editorconfig:/usr/src/app/.editorconfig
- ./bin:/usr/src/app/bin
- ./composer.json:/usr/src/app/composer.json
- ./composer.lock:/usr/src/app/composer.lock
- ./src:/usr/src/app/src
- ./tests:/usr/src/app/tests
- ./tools:/usr/src/app/tools
- ./vendor:/usr/src/app/vendor
- ./vendor-bin:/usr/src/app/vendor-bin
- "$HOME/.cache/composer:/tmp/composer_cache"
environment:
COMPOSER_CACHE_DIR: "/tmp/composer_cache"
COMPOSER_ROOT_VERSION: 'dev-master'
# Basic config for CLI commands
PHP_INI_ERROR_REPORTING: "E_ALL"
PHP_INI_MEMORY_LIMIT: "1g"
PHP_INI_MAX_EXECUTION_TIME: 3600
# Enable Opcache + JIT
PHP_INI_OPCACHE__ENABLE_CLI: 1
PHP_INI_OPCACHE__MEMORY_CONSUMPTION: 256
PHP_INI_OPCACHE__VALIDATE_TIMESTAMPS: 0
PHP_INI_JIT_BUFFER_SIZE: "256m"
Loading

0 comments on commit 605d3ef

Please sign in to comment.