serverless-mysql icon indicating copy to clipboard operation
serverless-mysql copied to clipboard

Types definition for Typescript

Open xamoulin opened this issue 7 years ago • 7 comments

That's it!

xamoulin avatar Sep 11 '18 21:09 xamoulin

+1

liam-betsworth avatar Feb 22 '19 19:02 liam-betsworth

I've tested with [email protected]. It seem to work

deptno avatar Apr 25 '19 03:04 deptno

I'm only able to import with

import create = require('serverless-mysql')

and my intellisense can't seem to import the type ServerlessMysql - is this expected?

shrugs avatar Apr 26 '19 22:04 shrugs

Additionally, the Transaction is actually a function returning that interface, not an object, so the existing type of

transaction: Transaction

should be

transaction(): Transaction

and

commit(): Promise<any>

could be

commit(): Promise<any[]>

shrugs avatar Apr 26 '19 22:04 shrugs

@shrugs > import the type ServerlessMysql - is this expected?

Not expected, definition is very initial version, so many modifications will need more.

Can you review the commit? I applied your comment, https://github.com/deptno/serverless-mysql/commit/32df25f2f4d52d4c78a219d32277bda0e38c5c26

deptno avatar Apr 27 '19 04:04 deptno

Any additional help with TypeScript definitions would be greatly appreciated.

jeremydaly avatar Apr 27 '19 05:04 jeremydaly

I made these types for my own use. Something like them may be useful in the next iteration of this:

export interface DbQuery {
    /**
     * Template query
     */
    sql: string;

    /**
     * Values for template query
     */
    values?: any[];

    timeout: number;
}

/**
 * Return type from ServerlessMysql#query after performing a SQL INSERT
 */
export interface DbInsertResult {
    insertId: number;
}

/**
 * Return type from ServerlessMysql#query after performing a SQL DELETE
 */
export interface DbDeleteResult {
    affectedRows: number;
}

/**
 * Return type from ServerlessMysql#query after performing a SQL UPDATE
 */
export interface DbUpdateResult {
    changedRows: number;
}

/**
 * Return type from ServerlessMysql#query after performing a SQL SELECT
 * (Array of objects containing the requested table fields.)
 */
export type DbSelectResult = Array<any>;

kernwig avatar Jun 04 '19 20:06 kernwig