Skip to content

Commit

Permalink
db clone
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-north committed Nov 20, 2017
0 parents commit eec9f99
Show file tree
Hide file tree
Showing 13 changed files with 1,115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.sqlite
node_modules
dist
!master.sqlite
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nvm use 9
Binary file added master.sqlite
Binary file not shown.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "mikeworks-sql",
"version": "0.0.0",
"description": "Mike.Works SQL Fundamentals Course",
"main": "index.js",
"repository": "https://github.com/mike-north/sql-fundamentals.git",
"author": "Mike North <michael.l.north@gmail.com> (https://mike.works)",
"license": "NOLICENSE",
"private": true,
"engines": {
"node": ">= 9"
},
"scripts": {
"start": "scripty",
"build": "scripty"
},
"dependencies": {
"chalk": "^2.3.0",
"commander": "^2.11.0",
"debug": "^3.1.0",
"express": "^4.16.2",
"sqlite3": "^3.1.13",
"scripty": "^1.7.2"
},
"devDependencies": {
"@types/chalk": "^2.2.0",
"@types/commander": "^2.11.0",
"@types/debug": "0.0.30",
"@types/node": "^8.0.53",
"@types/sqlite3": "^3.1.1",
"typescript": "^2.6.1"
}
}
2 changes: 2 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
tsc
3 changes: 3 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
npm run build
node dist/index.js
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { join } from "path";

export const PROJECT_ROOT = join(__dirname, '..');
export const MASTER_DB_NAME = 'master.sqlite';
export const MASTER_DB_FILE = join(PROJECT_ROOT, MASTER_DB_NAME);
22 changes: 22 additions & 0 deletions src/db/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { promisify } from "util";
import * as path from "path";
import * as fs from "fs";
import * as debug from 'debug';
import { PROJECT_ROOT, MASTER_DB_FILE } from "../constants";
import { dbPath } from "./utils";

const copyFile = promisify(fs.copyFile);
const exists = promisify(fs.exists);

const log = debug('db:setup');

export async function initializeDb(dbName = 'dev') {
let pth = dbPath(dbName);
let doesExist = await exists(pth);
if (!doesExist) {
log(`Database ${dbName} was not found at ${pth}... creating it now`);
await await copyFile(MASTER_DB_FILE, pth);
} else {
log(`Database ${dbName} was found at ${pth}...`);
}
}
4 changes: 4 additions & 0 deletions src/db/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as path from 'path';
import { PROJECT_ROOT } from "../constants";

export const dbPath = (name: string) => path.join(PROJECT_ROOT, `${name}.sqlite`);
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { existsSync } from "fs";
import * as commander from 'commander';
import { PROJECT_ROOT } from "./constants";
import { initializeDb } from "./db/setup";
import chalk from 'chalk';

const pkg = require('../package.json');

const app = commander
.version(pkg.version)
.parse(process.argv);

(async function main() {
await initializeDb('dev');
}())
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"inlineSourceMap": true,
"moduleResolution": "node",
"outDir": "dist",
"strict": true,
"allowJs": true
},
"include": [
"src"
]
}
Loading

0 comments on commit eec9f99

Please sign in to comment.