{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#hide\n",
    "from alphalib.data.loader import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Welcome to alphalib\n",
    "\n",
    "> A library for your daily data engineering and data science routines."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This file will become your README and also the index of your documentation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Install"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`pip install alphalib"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## How to use"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ingest from Excel to `accounts` table in PostgreSQL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2020-12-12 21:26:59,943 INFO(): {'user_id': INTEGER(), 'username': VARCHAR(length=50), 'password': VARCHAR(length=50), 'email': VARCHAR(length=255), 'created_on': TIMESTAMP(), 'last_login': TIMESTAMP()}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Total records in data/accounts.xlsx - 100\n",
      "user_id - 100\n",
      "username - 100\n",
      "password - 100\n",
      "email - 100\n",
      "created_on - 1\n",
      "last_login - 1\n"
     ]
    }
   ],
   "source": [
    "# Ingest from Excel to `accounts` table in PostgreSQL\n",
    "excel_source = file_sources.get(FileSource.Excel, file_path=\"data/accounts.xlsx\")\n",
    "config = {\n",
    "    'host': 'localhost',\n",
    "    'port': 5432,\n",
    "    'db': 'testdb',\n",
    "    'user': 'user1',\n",
    "    'password': 'userpwd'\n",
    "}\n",
    "pgsql_target = db_targets.get(DatabaseTarget.PostgreSQL, **config)\n",
    "ingest(excel_source, pgsql_target, 'accounts')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ingest from CSV to `accounts` table in MySQL"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2020-12-12 21:35:29,017 INFO(): {'user_id': INTEGER(), 'username': VARCHAR(length=50), 'password': VARCHAR(length=50), 'email': VARCHAR(length=255), 'created_on': TIMESTAMP(), 'last_login': TIMESTAMP()}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Total records in data/accounts.csv - 100\n",
      "user_id - 100\n",
      "username - 100\n",
      "password - 100\n",
      "email - 100\n",
      "created_on - 1\n",
      "last_login - 1\n"
     ]
    }
   ],
   "source": [
    "# Ingest from CSV to `accounts` table in MySQL\n",
    "csv_source = file_sources.get(FileSource.CSV, file_path=\"data/accounts.csv\")\n",
    "config = {\n",
    "    'host': 'localhost',\n",
    "    'port': 3306,\n",
    "    'db': 'testdb',\n",
    "    'user': 'user1',\n",
    "    'password': 'userpwd'\n",
    "}\n",
    "mysql_target = db_targets.get(DatabaseTarget.MySQL, **config)\n",
    "ingest(csv_source, mysql_target, 'accounts')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
