MySQL connection in Deno


Let’s move into another interesting sections, the database where we store information processed. In this post we are connecting MySQL local database using denodrivers.

APP

Our app is a simple Todo application, which store Todo’s in a MySQL database.

Denodrivers

This is a third party module for deno which will help us to build a connection to MySQL db. We are going todo the following

  • create a configuration
  • Insert,Update,Delete
  • Querying database

Configuration

Usually we kept the database file under a config folder, the name of our file will database.ts and content s follows

import { Client } from "https://deno.land/x/mysql/mod.ts";
const client = await new Client().connect({
  hostname: "127.0.0.1",
  username: "root",
  db: "todo_collections",
  poolSize: 3, // connection limit
  password: "123",
});

export default  { client }

You have to specify the host which is localhost, user and password, database name (you should create them first) and we are ready for the controllers.

Published by

Manoj

A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.