utopia-php / database Goto Github PK
View Code? Open in Web Editor NEWLite & fast micro PHP database abstraction library that is **easy to use**.
License: MIT License
Lite & fast micro PHP database abstraction library that is **easy to use**.
License: MIT License
$resp = $DB::updateDocumentBy('db', 'collection', [
Query.select(['foo', 'bar'])
], {
'bar': 'bla',
'splash': 'hash'
});
Alternate way for SELECT statement when Document ID isn't available. Might be slower in terms of a INNER JOIN not looking for _uid as a PRIMARY KEY.
Allows for more natural thinking in programming, and for example, updateDocumentBy APIKey or any other UNIQUE Column, in our case, in a MariaDB Table.
I thought something like this
Thoughts?
$db->count(
Audit::COLLECTION,
[
new Query('column1', Query::EQUALS, ['test'],
new Query('column2', Query::EQUALS, ['a', 'b']
]
);
Will produce following conditions in the SQL query:
AND table_main.column1 = 'test'
AND table_main.column2 = 'a'
OR table_main.column2 = 'b'
AND table_main.column1 = 'test'
AND
(
table_main.column2 = 'a'
OR table_main.column2 = 'b'
)
see above.
Example from the complete query:
SELECT COUNT(1) as sum
FROM (
SELECT 1
FROM project_console_internal.audit table_main
WHERE 1=1
AND 1=1
AND table_main.resource = :attribute_0_0_resource
AND table_main.event = :attribute_1_0_event
OR table_main.event = :a
) table_count
Version 0.10.x
PHP 8.0.x
MacOS
No response
In several places in Appwrite, we have to do:
$filterQueries = Query::groupByType($queries)['filters'];
$response->dynamic(new Document([
'users' => $dbForProject->find('users', $queries),
'total' => $dbForProject->count('users', $filterQueries, APP_LIMIT_COUNT),
]), Response::MODEL_USER_LIST);
It would be much cleaner to have Utopia\Database\Database->count()
grab only the filters so that the code can be simplified to:
- $filterQueries = Query::groupByType($queries)['filters'];
$response->dynamic(new Document([
'users' => $dbForProject->find('users', $queries),
- 'total' => $dbForProject->count('users', $filterQueries, APP_LIMIT_COUNT),
+ 'total' => $dbForProject->count('users', $queries, APP_LIMIT_COUNT),
]), Response::MODEL_USER_LIST);
Adapter to support using AWS DynamoDB database.
DynamoDB is one of the most common highly performant NoSQL database services.
Backed by the resiliency of AWS, many teams choose to have DynamoDB as their production database.
Supporting DynamoDB will ensure that our users can use the service seamlessly from within the utopia framework.
This feature is inline with the maintainer AppWrite's vision to add support for DynamoDB database
I will be following guide to Add New Database Adapter
Each adapter must implement the getIntLimit()
method, but it isn't enforced due to how we interpret $size
for integer attributes.
In the case of strings, $size
is pretty obvious - the length of the string. However, for integers (and before BIGINT), we just set $size = 0
, so this check in createAttribute()
would never actually prevent PDO from throwing the database exception:
database/src/Database/Database.php
Lines 433 to 437 in af512b7
Options to enforce int limit:
getIntLimit()
as a filter when creating/updating documentsUtopia\Database
exceptionThe SQL adapter including Maria/MySQL/SQLite should support the Contains query. I.E. attribute LIKE '%something%'
Forgive me if I missed it somewhere, but I don't see any reason that the SQL connector doesn't already support "Contains" queries. The syntax is well know, supported by all 3 supported SQL engines(and most others), and simple and consistent across all versions of SQL.
So far as I can tell, this would only require changing 1 line of code to provide support, and one or two others to enable that support(instead of rejecting it).
src/Database/Adapter/SQL.php -> bindConditionValue, add:
Query::TYPE_CONTAINS => '%' . $this->escapeWildcards($value) . '%',
Please let me know if there is a reason this isn't already done. It seems so obvious that I can't help but think there is a reason it's not already done, and that I'm the one missing something obvious.
If needed, I'd be happy to clone, modify, and submit a PR.
Adding the option to select n items as random.
The implementation would look something like this
$documents = static::getDatabase()->find('movies', [
Query::random(),
Query::limit(5),
]);
Or with limit as the random parameter.
$documents = static::getDatabase()->find('movies', [
Query::random(5),
]);
Adapter are required for:
I first intend to add it as a feature for Appwrite database endpoints.
Also, It can be helpful in games, for example.
An adapter for Apache CouchDB
The point of this repository is to provide a "PHP database abstraction library". So, I intend to provide support for CouchDB. You're welcome.
When I am installing the module for local development, I am getting the issue swoole coroutine client not found despite the the fact it has been installed and present in the vendor
Tried with Utopia-php/swoole as well
Any steps I am missing or is it a bug in the code?
No error
Getting error
Version 0.10.x
PHP 8.0.x
Linux
No response
It would make sense for the Query/Queries Validators in Appwrite to be moved into Utopia so they can be reused.
The last Query Refactor had some changes that could be improved, but we rushed forward due to lack of time.
Variadic functions can be confusing. It's much clearer to use arrays instead:
- public static function getByType(array $queries, string ...$types): array
+ public static function getByType(array $queries, array $types): array
This fields auto generate on insert / update
It can be usefull to force them via data
like
{
...otherFields,
"$createdAt": "string or timestamp"
}
In case of migration for others platform, without this we need to inject data directly on MariaDB, or we'll loose this information or if we simply need to change it for any other reason
GitHub has recently rolled out a public beta for their issue forms feature. This would allow you to create interactive issue templates and validate them ๐คฏ.
Appwrite currently uses the older issue template format. Your task is to create GitHub issue forms for this repository. Please use Appwrite's issue templates as a reference for this PR.
.github/ISSUE_TEMPLATE/bug.yaml
.github/ISSUE_TEMPLATE/documentation.yaml
.github/ISSUE_TEMPLATE/feature.yaml
If you need any help, reach out to us on our Discord server.
Are you ready to work on this issue? ๐ค Let us know, and we will assign it to you ๐
Happy Appwriting!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.