From 7c91f7aa7ca6833e85a9654812eb02ef823d4cc3 Mon Sep 17 00:00:00 2001 From: Netto Farah Date: Tue, 14 Jan 2020 15:57:57 -0800 Subject: [PATCH] Expose inferSchemaObject and inferTableObject --- src/index.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index bad92fc..059d650 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { tableToTS } from './typescript' +import { tableToTS, Table } from './typescript' import { MySQL } from './mysql-client' import prettier from 'prettier' import pkg from '../package.json' @@ -42,3 +42,14 @@ export async function inferSchema(connectionString: string): Promise { const code = [header(interfaces.some(i => i.includes('JSON'))), ...interfaces].join('\n') return pretty(code) } + +export async function inferTableObject(connectionString: string, table: string): Promise { + const db = new MySQL(connectionString) + return db.table(table) +} + +export async function inferSchemaObject(connectionString: string) { + const db = new MySQL(connectionString) + const tables = await db.allTables() + return tables +}