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.