feat(services): update getBySlug
function in MySQL services
The `getBySlug` function originally returned a single database model by slug from the MySQL handler. It has been updated to return a list of database models by slug name. Error handling for failed query executions is also included. Signed-off-by: Mathis <yidhra@tuta.io>
This commit is contained in:
parent
bdba2f6e29
commit
5afb6e22bf
@ -569,20 +569,20 @@ const MySqlService = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves a database model by slug from a given MySQL handler.
|
||||
* Retrieves a list of database models by slug name.
|
||||
*
|
||||
* @param {MysqlHandler} handler - The MySQL handler instance.
|
||||
* @param {string} modelSlug - The slug of the model to retrieve.
|
||||
* @return {Promise<IDbModel>} A promise that resolves with the retrieved model.
|
||||
* @throws {Error} If there was an error executing the query.
|
||||
* @param {MysqlHandler} handler - The MySQL handler used to execute the query.
|
||||
* @param {string} modelSlug - The slug name of the model to retrieve.
|
||||
* @return {Promise<Array<IDbModel>>} - A promise that resolves to an array of database models.
|
||||
* @throws {Error} - If an error occurs during the execution of the query.
|
||||
*/
|
||||
getBySlug(handler: MysqlHandler, modelSlug: string): Promise<IDbModel> {
|
||||
getBySlug(handler: MysqlHandler, modelSlug: string): Promise<Array<IDbModel>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const _sql = "SELECT * FROM models WHERE slug_name VALUES(?)";
|
||||
const _values = [modelSlug];
|
||||
try {
|
||||
handler.execute(_sql, _values).then((result) => {
|
||||
return resolve(result as unknown as IDbModel);
|
||||
return resolve(result as unknown as Array<IDbModel>);
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
reject(err as Error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user