Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db-manager): improve type definition #543

Merged
merged 1 commit into from
Jul 24, 2020
Merged

fix(db-manager): improve type definition #543

merged 1 commit into from
Jul 24, 2020

Conversation

munierujp
Copy link
Contributor

What does this implement/fix? Explain your changes.

[@middy/db-manager] Provide default type definition like @middy/secrets-manager.

Then, default import is available in TypeScript.

import middy from '@middy/core'
import lambda from 'aws-lambda'
import Knex from 'knex'
import dbManager from '@middy/db-manager'

interface Context extends lambda.Context {
  db: Knex
}

const handler = middy(async (
  event: any,
  context: Context,
  callback: lambda.Callback<any>
): Promise<void> => {
  const { db } = context
  const users = await db.select('*').from('users')
  console.log(users)
})

handler.use(dbManager({
  config: {
    client: 'mysql',
    connection: {
      host: '127.0.0.1',
      user: 'your_database_user',
      password: 'your_database_password',
      database: 'myapp_test'
    }
  }
}))

Does this close any currently open issues?

Any relevant logs, error output, etc?

none

Any other comments?

none

Where has this been tested?

Node.js Versions: v12.14.0

Middy Versions: 1.0.0

AWS SDK Versions: 2.656.0

Todo list

none

@willfarrell willfarrell merged commit 95fd5bd into middyjs:master Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants