All files / blong-int-adapter/mysql/adapter/sql sqlTableCreate.ts

100% Statements 25/25
75% Branches 3/4
100% Functions 1/1
100% Lines 25/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 261x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import {handler} from '@feasibleone/blong';
 
/**
 * sqlTableCreate — creates the `item` test table in the blong-integration
 * database if it does not already exist.
 * This handler is called from integration tests to set up the test schema.
 */
export default handler(
    () =>
        async function sqlTableCreate(
            _params: Record<string, never>,
            _$meta: Record<string, unknown>,
        ): Promise<{table: string; existed: boolean}> {
            const existed = await this.config?.context?.queryBuilder?.schema.hasTable('item');
            if (!existed) {
                // eslint-disable-next-line @typescript-eslint/no-explicit-any
                await this.config?.context?.queryBuilder?.schema.createTable('item', (table: any) => {
                    table.increments('itemId');
                    table.string('itemName', 255).notNullable();
                    table.text('itemDescription').nullable();
                });
            }
            return {table: 'item', existed: existed ?? false};
        },
);