A TypeScript library providing a decorator-based approach to execute MySQL queries using named placeholders. Current version is 1.1.6 (August 2019), with no updates since. It simplifies query execution by allowing decorators on methods, returning rows or assembled objects via custom assemblers. Key differentiators: lean API with no ORM overhead, supports parameterized queries with named placeholders, and integrates with any MySQL connection. However, it depends on the deprecated 'mysql' package (not 'mysql2'), lacks connection pooling, and has minimal documentation and community support. Suitable for small projects but not recommended for production due to maintenance status.
npm install mysql-query-decoratorNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Configures a MySQL connection, defines a User class with an assembler, and uses the @query decorator to fetch a user by ID.
Ensure that methods with named parameters return an object mapping parameter names to values. For queries without parameters, the method body can be empty.
Consider migrating to 'mysql2' or a more modern ORM/query builder. The 'mysql' package is unmaintained.
Check compatibility with your TypeScript version. You may need to set 'experimentalDecorators': true in tsconfig.json.
Ensure the assembler's 'assemble' method returns the correct type as expected by the decorator's generic parameter.
import { MYSQLQuery } from 'mysql-query-decorator';Ensure MYSQLQuery.use({ host: '...', user: '...', database: '...' }) is called before any decorated query method.Make the method return an object with keys matching the placeholder names, e.g., return { id } for ':id'.Add 'experimentalDecorators': true to tsconfig.json compilerOptions.