Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ typings/

# VScode settings
.vscode/settings.json

tests/.phpunit.cache/test-results
46 changes: 46 additions & 0 deletions lib/AppFramework/Db/Attribute/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH
* SPDX-FileContributor: Carl Schwan
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Maps\AppFramework\Db\Attribute;

use Attribute;
use OCP\AppFramework\Attribute\Consumable;
use OCP\DB\Types;

/**
* Attribute for mapping a property in an entity to a database column.
*
* ```php
* #[Entity(name: 'my_entity']
* final class MyEntity {
* #[Column(name: 'my_column', type: Types::String, default: '')]
* public string $myColumn = '';
* }
* ```
*
* @since 35.0.0
*/
#[Attribute(Attribute::TARGET_PROPERTY)]
#[Consumable(since: '35.0.0')]
final readonly class Column {
public function __construct(
/** @param non-empty-string $name The name of the column in the database. */
public string $name,
/** @param Types::* $type The type of the column in the database. */
public string $type,
/** @param ?int $length The length of the column (relevant for Types::STRING) */
public ?int $length = null,
Comment thread
CarlSchwan marked this conversation as resolved.
/** @param bool $nullable Whether the column is nullable in the database */
public bool $nullable = false,
/** @param mixed $default The default value for the column in the database. */
public mixed $default = null,
) {
}
}
37 changes: 37 additions & 0 deletions lib/AppFramework/Db/Attribute/Entity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH
* SPDX-FileContributor: Carl Schwan
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Maps\AppFramework\Db\Attribute;

use Attribute;
use OCP\AppFramework\Attribute\Consumable;

/**
* Attribute for marking a class as an entity mapped to some database table.
*
* ```php
* #[Entity(name: 'my_entity')]
* final class MyEntity {
* #[Column(name: 'my_column', type: Types::String, default: '')]
* public string $myColumn = '';
* }
* ```
*
* @since 35.0.0
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[Consumable(since: '35.0.0')]
final readonly class Entity {
public function __construct(
/** @param non-empty-string $name */
public string $name,
) {
}
}
39 changes: 39 additions & 0 deletions lib/AppFramework/Db/Attribute/Id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH
* SPDX-FileContributor: Carl Schwan
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Maps\AppFramework\Db\Attribute;

use Attribute;
use OCP\AppFramework\Attribute\Consumable;
use OCP\Snowflake\ISnowflakeGenerator;

/**
* Attribute for marking a column as a primary id.
*
* ```php
* #[Entity(name: 'my_entity']
* final class MyEntity {
* #[Id(generatorClass: ISnowflakeGenerator::class)]
* #[Column(name: 'id', type: Types::BIGINT)]
* public string $id = '';
* }
* ```
*
* @since 35.0.0
*/
#[Attribute(Attribute::TARGET_PROPERTY)]
#[Consumable(since: '35.0.0')]
final readonly class Id {
public function __construct(
/** @param class-string<ISnowflakeGenerator> $generatorClass */
public ?string $generatorClass = null,
) {
}
}
Loading
Loading