mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement api methods
This commit is contained in:
parent
cd38fe6fbe
commit
42c4118e46
1 changed files with 108 additions and 6 deletions
|
|
@ -22,11 +22,113 @@ class Identity
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`time` INTEGER NOT NULL,
|
`time` INTEGER NOT NULL,
|
||||||
`active` INTEGER NOT NULL,
|
|
||||||
`name` VARCHAR(255),
|
`name` VARCHAR(255),
|
||||||
`crt` TEXT NOT NULL,
|
`crt` TEXT NOT NULL,
|
||||||
`key` TEXT NOT NULL
|
`key` TEXT NOT NULL
|
||||||
)
|
)
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function add(
|
||||||
|
?string $crt,
|
||||||
|
?string $key,
|
||||||
|
?string $name = null,
|
||||||
|
?int $time = null
|
||||||
|
): int
|
||||||
|
{
|
||||||
|
$query = $this->_connection->prepare(
|
||||||
|
'INSERT INTO `identity` (
|
||||||
|
`time`,
|
||||||
|
`name`,
|
||||||
|
`crt`,
|
||||||
|
`key`
|
||||||
|
) VALUES (
|
||||||
|
:time,
|
||||||
|
:name,
|
||||||
|
:crt,
|
||||||
|
:key
|
||||||
|
)'
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->execute(
|
||||||
|
[
|
||||||
|
':time' => $time ? $time : time(),
|
||||||
|
':name' => $name,
|
||||||
|
':crt' => $crt,
|
||||||
|
':key' => $key
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return intval(
|
||||||
|
$this->_connection->lastInsertId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(
|
||||||
|
int $id
|
||||||
|
): int
|
||||||
|
{
|
||||||
|
$query = $this->_connection->prepare(
|
||||||
|
'DELETE FROM `identity` WHERE `id` = :id'
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->execute(
|
||||||
|
[
|
||||||
|
':id' => $id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $query->rowCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(
|
||||||
|
int $id
|
||||||
|
): ?object
|
||||||
|
{
|
||||||
|
$query = $this->_connection->prepare(
|
||||||
|
'SELECT * FROM `identity` WHERE `id` = :id'
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->execute(
|
||||||
|
[
|
||||||
|
':id' => $id
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($identity = $query->fetch())
|
||||||
|
{
|
||||||
|
return $identity;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function find(
|
||||||
|
string $name = '',
|
||||||
|
int $start = 0,
|
||||||
|
int $limit = 1000
|
||||||
|
): array
|
||||||
|
{
|
||||||
|
$query = $this->_connection->prepare(
|
||||||
|
sprintf(
|
||||||
|
'SELECT * FROM `identity`
|
||||||
|
WHERE `name` LIKE :name
|
||||||
|
ORDER BY `name` ASC
|
||||||
|
LIMIT %d,%d',
|
||||||
|
$start,
|
||||||
|
$limit
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$query->execute(
|
||||||
|
[
|
||||||
|
':name' => sprintf(
|
||||||
|
'%%%s%%',
|
||||||
|
$name
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $query->fetchAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue