Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
231 commits
Select commit Hold shift + click to select a range
b1d8b08
created new Node/Express app
a-lmx Sep 15, 2015
18bbe6c
added node_modules to gitignore
a-lmx Sep 15, 2015
27ef18e
pseudo-coded Customer routes
a-lmx Sep 15, 2015
af553c8
pseudo-coded start of Movie routes
a-lmx Sep 15, 2015
400fc5b
removed space for formatting
a-lmx Sep 16, 2015
5e0edc0
schema set up with updates to endpoints for movies and rentals
acmei Sep 17, 2015
0f9ffc1
added sqlite3 and mocha
a-lmx Sep 17, 2015
fea2c14
created schema
a-lmx Sep 17, 2015
ad03cec
created dev db with schema
a-lmx Sep 17, 2015
16439d9
moved seed data files to utils dir
a-lmx Sep 17, 2015
0836ee9
wrote script to seed movies
a-lmx Sep 17, 2015
988bfc0
updated db with movie data
a-lmx Sep 17, 2015
3d7104c
seeded db with customer data
a-lmx Sep 17, 2015
a2213ff
removed users routes and references and added /zomg route
acmei Sep 17, 2015
c5dd50e
checkout and checkin endpoints refined
acmei Sep 17, 2015
94b399f
registered movie_routes
a-lmx Sep 17, 2015
33b07c2
added /movies route -- IT WORKS
a-lmx Sep 17, 2015
d096d0b
working /movies route that returns list of all movies
a-lmx Sep 17, 2015
3ae537b
added example code to movie_tests
a-lmx Sep 17, 2015
8205495
added notes re: registered routes
a-lmx Sep 17, 2015
4249b92
added /customers endpoint to retrieve customer data in json
acmei Sep 17, 2015
e5ce4b9
made pnm start command use nodemon
a-lmx Sep 18, 2015
6e710f8
created adapter to talk to database and perform CRUD operations
a-lmx Sep 18, 2015
4c8d4de
created models for movie and customer that use the database-adapter
a-lmx Sep 18, 2015
faefd46
modified routes to use models and functions as defined in the databas…
a-lmx Sep 18, 2015
f2ea151
added find_by method in database adapter, working for customer find_b…
acmei Sep 18, 2015
460a7df
added find_by movie title endpoint
acmei Sep 18, 2015
7b67adc
added where function
a-lmx Sep 18, 2015
47fdf74
added debugger route to test function of database-adapter
a-lmx Sep 18, 2015
0c3df75
changed test folder name and added movie model test file
acmei Sep 18, 2015
562010c
changed find_by query to use LIKE to take account for casing
acmei Sep 18, 2015
b4a3edd
WIP limit function
acmei Sep 18, 2015
d40c3ae
added subset function to obtain movies sorted by, limit, and offset
acmei Sep 18, 2015
4db59ea
removed comment
a-lmx Sep 18, 2015
f308653
added subset endpoint
a-lmx Sep 18, 2015
26dc95b
added subset function
a-lmx Sep 18, 2015
1a12821
debugging movie test file
a-lmx Sep 18, 2015
a6debf3
added go -b
acmei Sep 20, 2015
725400b
testing for customers model WIP
acmei Sep 20, 2015
f921409
testing for customers find_all
acmei Sep 20, 2015
1b4a126
added testing for customers.subset and removed console.log from subse…
acmei Sep 21, 2015
13fb422
added first test for
a-lmx Sep 21, 2015
34a720c
Merge pull request #1 from acmei/customers-tests
arhx Sep 21, 2015
a550937
WIP customers create function
acmei Sep 21, 2015
17fa5c8
WIP customers create function
acmei Sep 21, 2015
b03cc7b
got test working
a-lmx Sep 21, 2015
dafad20
removed comments in function
a-lmx Sep 21, 2015
5843898
got test and function working for update
a-lmx Sep 21, 2015
884d0ea
added Rental model
a-lmx Sep 21, 2015
5686f85
added checkout route and pseudocode for inventory check
a-lmx Sep 21, 2015
e1eecc8
changed variable name from pineapple to res
a-lmx Sep 21, 2015
fa98a34
added where to namespace debugger where route
a-lmx Sep 21, 2015
cb18c02
added rental_movies_count to checkout route
a-lmx Sep 21, 2015
60a8540
fixed merge conflict
a-lmx Sep 21, 2015
c905a12
added unit tests for subset, create, and update
a-lmx Sep 21, 2015
49dd74d
Merge pull request #3 from acmei/movies-unit-test
acmei Sep 21, 2015
b964b01
registered rentals routes
a-lmx Sep 21, 2015
ee62581
clarified comment purpose
a-lmx Sep 21, 2015
37b5b48
WIP; fixing logic on checkout route
a-lmx Sep 21, 2015
b34e62c
Merge branch 'acw+ar/master' of github.com:acmei/C3Projects--VideoSto…
a-lmx Sep 21, 2015
bd2edba
used concat function in place of loop to add arrays
a-lmx Sep 21, 2015
6c747f6
WIP; figuring out callbacks
a-lmx Sep 21, 2015
77092d9
WIP rentals post action
acmei Sep 21, 2015
0659edb
added async to packages
a-lmx Sep 21, 2015
f99afd4
WIP; working on getting functions to execute synchronously
a-lmx Sep 21, 2015
0580416
got the checkout route operational
a-lmx Sep 22, 2015
41aff02
Merge pull request #4 from acmei/sync-ar
acmei Sep 22, 2015
2fd914a
added comments and removed extraneous code
acmei Sep 22, 2015
27cc703
added rentals seed data
acmei Sep 22, 2015
21c72df
added rentals seed data
acmei Sep 22, 2015
d78cc1d
added rentals/:title route
a-lmx Sep 22, 2015
7015654
added where_in function
a-lmx Sep 22, 2015
acfa0d6
added necessary parameter to movie tests
a-lmx Sep 22, 2015
155fed1
fixed variable name merge conflict
a-lmx Sep 22, 2015
3c79cd0
changed where function back to selecting *
a-lmx Sep 22, 2015
7a4a8a0
added space before curly brace
a-lmx Sep 22, 2015
cf8ec8c
changed where test back to not taking desiredColumns parameter
a-lmx Sep 22, 2015
7805ed7
got rentals/:title route working
a-lmx Sep 22, 2015
162c184
modifications to dev db
a-lmx Sep 22, 2015
5e6dc90
Merge pull request #5 from acmei/rentals-by-title/ar
acmei Sep 22, 2015
31c5aa2
refactored /:title route to take advantage of hoisted variables
a-lmx Sep 23, 2015
ba87dc5
added movies rented (current and past) to customers/:id endpoint
acmei Sep 23, 2015
1f56626
edited rentals seed data
acmei Sep 23, 2015
3adfe56
Merge pull request #8 from acmei/rentals-seed
acmei Sep 23, 2015
545125a
Merge pull request #6 from acmei/rentals-by-title/ar
acmei Sep 23, 2015
c6260e5
adding customers object to movies/:title route; WIP
a-lmx Sep 23, 2015
a8079aa
added current and past renters to customers object
a-lmx Sep 23, 2015
9cff1fa
refactoring of customers to use only callbacks, no async
acmei Sep 23, 2015
5e6df69
removing async from customers.js and adding order_by adapter function
acmei Sep 23, 2015
2911bcb
Merge pull request #11 from acmei/customers-refactor
arhx Sep 23, 2015
05789e9
Merge pull request #10 from acmei/movie-title-order/ar
acmei Sep 23, 2015
9ad14b8
changed schema of rentals table
a-lmx Sep 23, 2015
bdf1498
updated routes and database adapter to use new rentals schema
a-lmx Sep 23, 2015
e40cbb9
modified seed data to allow more meaningful testing
a-lmx Sep 23, 2015
85c1159
changed rental.where to rental.order_by to return ordered results
a-lmx Sep 23, 2015
9ce205c
added returned_date to pastRental movie objects
a-lmx Sep 23, 2015
fa94f99
WIP adding sorting to movie endpoint
acmei Sep 23, 2015
bc6ac16
refactored statement in order_by function
a-lmx Sep 23, 2015
82db4b0
modified seed data to make debugging easier
a-lmx Sep 23, 2015
756306e
added sort by customer name to /:title/:order route
a-lmx Sep 23, 2015
055511f
Merge pull request #12 from acmei/add-sorting
acmei Sep 23, 2015
cf7db1b
starting overdue for rentals, removed console.logs in movies
acmei Sep 23, 2015
31b4c99
added /overdue route, moved to top of file to avoid collisions
a-lmx Sep 23, 2015
55f394d
Merge pull request #13 from acmei/overdue
arhx Sep 23, 2015
5206124
added /checkin route
a-lmx Sep 23, 2015
e57f827
checked in movie, which changed db
a-lmx Sep 23, 2015
51ac524
Merge pull request #14 from acmei/check-in
acmei Sep 23, 2015
5501e7d
removing extraneous comments, console.logs, and brackets in where_in …
acmei Sep 23, 2015
a30ea3a
wrote test for GET /customers
a-lmx Sep 23, 2015
65244f3
added Supertest
a-lmx Sep 23, 2015
bd4eed2
added more tests for /customers endpoint
a-lmx Sep 23, 2015
89958a3
fixed db_cleaner in routes/customers tests
a-lmx Sep 24, 2015
16bb3d9
db setup
acmei Sep 24, 2015
79f7cb8
WIP customers/:id endpoint testing
acmei Sep 24, 2015
ac4731b
added tests for /movies route
a-lmx Sep 24, 2015
fd1a5cd
refactored customers subset unit test
acmei Sep 24, 2015
667a615
removed extraneous comment
acmei Sep 24, 2015
c85bc7b
added tests /movies/:sort_by/:number/:offset
a-lmx Sep 24, 2015
a12be9f
Merge pull request #16 from acmei/customers-tests
arhx Sep 24, 2015
e2affab
fixed merge conflict
a-lmx Sep 24, 2015
e8078a7
ran latest tests
a-lmx Sep 24, 2015
31d475e
Merge pull request #17 from acmei/movies-integration-tests
acmei Sep 24, 2015
f85d758
fixing merge conflicts
acmei Sep 24, 2015
008b3cd
Merge pull request #15 from acmei/debug+refactor
acmei Sep 24, 2015
eff81e7
added remaining tests for GET /movies/:sort_by/:number/:offset
a-lmx Sep 24, 2015
7c6c05c
Merge branch 'acw+ar/master' of github.com:acmei/C3Projects--VideoSto…
a-lmx Sep 24, 2015
e0e671a
removed console.log
a-lmx Sep 24, 2015
63a8e5b
wrote integration tests for GET /rentals/overdue
a-lmx Sep 24, 2015
b4922b6
debugging customer sorting tests
acmei Sep 24, 2015
72e0590
started creating tests for GET /rentals/:title; WIP
a-lmx Sep 24, 2015
8ebfbd7
Merge pull request #18 from acmei/movies-integration-tests
acmei Sep 24, 2015
e4a3474
fixing merge conflict
a-lmx Sep 24, 2015
c7fa571
fixed /customers/:id route to return movies sorted by checkout date; …
a-lmx Sep 24, 2015
ace430b
removed unused condition variable
a-lmx Sep 24, 2015
547b360
fixed /movies/:title/:order route to return sorted data
a-lmx Sep 24, 2015
d256703
removed unused order_by function
a-lmx Sep 24, 2015
54cd141
fixing merge conflicts
acmei Sep 24, 2015
81f8aae
WIP customers testing
acmei Sep 24, 2015
6434850
updated url parameter to be allowed sort order
a-lmx Sep 24, 2015
54b0f34
Merge pull request #19 from acmei/movies-integration-tests
acmei Sep 24, 2015
5113c43
WIP fixing customers tests after changes to routes code
acmei Sep 24, 2015
e441b41
fixing merge conflict
acmei Sep 24, 2015
b985944
fixed customers testing
acmei Sep 24, 2015
6f257f9
removed console.log from movies routes files and fixed test for movie…
acmei Sep 24, 2015
c4c7c0e
Merge pull request #21 from acmei/customers-tests
arhx Sep 24, 2015
3e7623b
added where and where_in unit tests for customers
acmei Sep 24, 2015
a8e7b71
added where_in method test for movies
acmei Sep 24, 2015
a3efd09
added find_all test for movies
acmei Sep 24, 2015
1a84622
fixed test typo
acmei Sep 24, 2015
eda9b02
Merge pull request #22 from acmei/customers-models-tests
arhx Sep 24, 2015
a9397fa
merge conflict in test.db
a-lmx Sep 24, 2015
b860301
added additional tests for GET /rentals/:title
a-lmx Sep 24, 2015
4bd9677
added tests for /customers/:sort_by/:number/:offset
a-lmx Sep 24, 2015
aaecf85
removed unused (practice) endpoint for POST create
a-lmx Sep 24, 2015
b0699f3
Merge pull request #23 from acmei/rentals-integration-tess
acmei Sep 24, 2015
28da25e
merge conflict in test.db
a-lmx Sep 24, 2015
4d9db4a
fixed comments in /customers/:sort_by/:number/:offset
a-lmx Sep 24, 2015
9684d49
Merge pull request #24 from acmei/customers-integration-tests
acmei Sep 24, 2015
ac1ae37
fixed checkout endpoint to take movie_title instead of movie_id
acmei Sep 24, 2015
b6ae46b
merge conlficts
acmei Sep 24, 2015
59f0c9b
Merge pull request #25 from acmei/checkout-fix
arhx Sep 24, 2015
3311c34
merge conflicts in test.db
a-lmx Sep 24, 2015
2fb38ef
merge conflicts in test.db
a-lmx Sep 24, 2015
c5180a7
removed async from rentals/:title endpoint
acmei Sep 24, 2015
4453a72
removed async from rentals/checkout endpoint
acmei Sep 24, 2015
822f512
uninstalled async
acmei Sep 24, 2015
0bc3d37
removed async requirement from movies routes file
acmei Sep 24, 2015
da436ff
Merge pull request #26 from acmei/remove-async
arhx Sep 24, 2015
43f4dda
added tests for PUT /rentals/checkin endpoint
a-lmx Sep 24, 2015
9347aa4
Merge branch 'acw+ar/master' of github.com:acmei/C3Projects--VideoSto…
a-lmx Sep 24, 2015
23148f0
Merge pull request #28 from acmei/rentals-integration-tess
acmei Sep 24, 2015
6b5fa92
added message display test for post method
acmei Sep 25, 2015
70be828
updated POST checkout method to charge per rental
acmei Sep 25, 2015
fd2b41e
updated post checkout message return test
acmei Sep 25, 2015
8e36f58
edited POST checkout test
acmei Sep 25, 2015
5b234d4
removed customer from rental routes testing
acmei Sep 25, 2015
07cee3f
removed customer variable
acmei Sep 25, 2015
722f370
ignore test.db
acmei Sep 25, 2015
8a565dc
Merge pull request #29 from acmei/checkout-test
arhx Sep 25, 2015
d29ea50
added comments to PUT checkin route
a-lmx Sep 25, 2015
9511821
created skeleton of endpoint-readme
a-lmx Sep 25, 2015
09f38c3
added all endpoints
a-lmx Sep 25, 2015
c113199
added get_customers sample to endpoint-readme
a-lmx Sep 25, 2015
53346c8
changed casing on json object from camel to snake
a-lmx Sep 25, 2015
a559090
added sample for GET 'customers/id'
a-lmx Sep 25, 2015
42bc7f3
fixed typo in file name
a-lmx Sep 25, 2015
eaf7c9e
fixed typo in file name
a-lmx Sep 25, 2015
2b32996
added formatting
a-lmx Sep 25, 2015
af60c11
added testing for customer_account credit decrementing
acmei Sep 25, 2015
95e32ed
removed movie requirement
acmei Sep 25, 2015
834b77e
Merge pull request #30 from acmei/checkout-test
acmei Sep 25, 2015
b0ac2f7
added sample for get_customers_sort_by_limit_offset
a-lmx Sep 25, 2015
c2f8b24
adding example as block of code
a-lmx Sep 25, 2015
3a75f8e
beautified json sample
a-lmx Sep 25, 2015
6204d1b
beautifed and included in-line all json examples
a-lmx Sep 25, 2015
d106cd6
added prose and sample for GET /movies
a-lmx Sep 25, 2015
5ea530f
removed sample json files
a-lmx Sep 25, 2015
a3e1049
formatting internal anchor
a-lmx Sep 25, 2015
e3840e1
formatting again WIP
a-lmx Sep 25, 2015
5bd6aaf
formatting again WIP
a-lmx Sep 25, 2015
18d083d
formatting again WIP
a-lmx Sep 25, 2015
cc728d6
formatted more of the endpoints with links
a-lmx Sep 25, 2015
d8397ea
changed case from camel to snake on object properties
a-lmx Sep 25, 2015
d80b29b
complete info on get movies/title/sort
a-lmx Sep 25, 2015
766adff
formatting
a-lmx Sep 25, 2015
a17f988
experimenting with formatting
a-lmx Sep 25, 2015
8589af8
experimenting with formatting
a-lmx Sep 25, 2015
14f38e0
experimenting with formatting
a-lmx Sep 25, 2015
686bd26
added example and prose for get movies/sort_by/limit/offset
a-lmx Sep 25, 2015
351726d
fixed typo; customer and movie routes documented
a-lmx Sep 25, 2015
9c267e1
added example and prose for get rentals/overdue
a-lmx Sep 25, 2015
04318b3
experimenting with formatting
a-lmx Sep 25, 2015
fe487e3
experimenting with formatting
a-lmx Sep 25, 2015
3570c46
added customers endpoints error handling and started rentals
acmei Sep 25, 2015
92da789
changed camel casing to snake case for json
a-lmx Sep 25, 2015
91258f2
added example and prose for get rentals/overdue
a-lmx Sep 25, 2015
e0218e9
added example and prose for post rentals/checkout
a-lmx Sep 25, 2015
5198ef8
more error handling
acmei Sep 25, 2015
4a94893
corrected typo
acmei Sep 25, 2015
c90512a
added example and prose for put rentals/checkin
a-lmx Sep 25, 2015
8bba5cb
added formatting to sample text
a-lmx Sep 25, 2015
18bdb80
edited error message for sorting
acmei Sep 25, 2015
eb7a8e7
edited error message for no results
acmei Sep 25, 2015
583bbbf
fixing casing on json responses in tests
a-lmx Sep 25, 2015
1db3d19
more editing of messages
acmei Sep 25, 2015
d6dde62
added instructions to our README.md
a-lmx Sep 25, 2015
952498b
added line to separate instructions from specs
a-lmx Sep 25, 2015
860697a
Merge pull request #32 from acmei/errors
arhx Sep 25, 2015
de66489
fixed instructions
a-lmx Sep 25, 2015
82c1fd5
fixed merge conflict
a-lmx Sep 25, 2015
a9001fa
Merge pull request #31 from acmei/endpoint-readme
arhx Sep 25, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
.DS_Store

# Let package.json handle dependencies
/node_modules

db/test.db
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ Alice & Anita

# Project: VideoStoreAPI

###How to run
1. Clone the repo.
2. Install all packages by running `npm install`.
3. See tests by running `npm test`.
4. See instructions for using our endpoints [here](./endpoint-readme.md).

-------------

The overall goal of this project is to create a system that a video store (remember those?) could use to track their inventory of rental videos and their collection of customers.

We will use [NodeJS](https://nodejs.org/en/) to construct a RESTful API. The goal of this API is to quickly serve information about the store's video collection, customer information, and to update rental status. This repository provides two JSON datafiles to serve as the initial seeds for this system.
Expand Down
71 changes: 71 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// Are we going to use this??
// register root routes
var routes = require('./routes/index');
app.use('/', routes);

// register movies routes
var movie_routes = require('./routes/movies');
app.use('/movies', movie_routes);

// register customer routes
var customer_routes = require('./routes/customers');
app.use('/customers', customer_routes);

// register rental routes
var rental_routes = require('./routes/rentals');
app.use('/rentals', rental_routes);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});


module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('C3Projects--VideoStoreAPI:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
107 changes: 107 additions & 0 deletions database_adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"use strict";

var sqlite3 = require('sqlite3').verbose(),
db_env = process.env.DB || 'development';

module.exports = {
find_all: function(callback) {
var db = new sqlite3.Database('db/' + db_env + '.db');
var statement = "SELECT * FROM " + this.table_name;

db.all(statement, function(err, res) {
if (callback) { callback(err, res); }
db.close();
});
},

// get returns one record, making this emulate Active Record's find_by
find_by: function(column, value, callback) {
var db = new sqlite3.Database('db/' + db_env + '.db');
var statement = "SELECT * FROM " + this.table_name + " WHERE " + column + " LIKE ?";

db.get(statement, value, function(err, res) {
if (callback) { callback(err, res); }
db.close();
});
},

// returns array of records
where: function(columns, values, callback) {
var db = new sqlite3.Database('db/' + db_env + '.db');
var where_statements = [];

// where_statements => ["city = ?", "state = ?"]
for (var i = 0; i < columns.length; i++) {
where_statements.push(columns[i] + " = ?");
}
// where_statement => "city = ? AND state = ?"
var where_statement = where_statements.join(" AND ");

var statement = "SELECT * FROM " + this.table_name + " WHERE " + where_statement;

db.all(statement, values, function(err, res) {
if (callback) { callback(err, res); }
db.close();
});
},

where_in: function(column, values, callback) {
var db = new sqlite3.Database('db/' + db_env + '.db');
var questionMarks = Array(values.length + 1).join('?').split('').join(', ');

var statement = "SELECT * FROM " + this.table_name + " WHERE " + column + " IN (" + questionMarks + ");";

db.all(statement, values, function(error, result) {
if (callback) { callback(error, result); }
db.close();
});
},

subset: function(column, queries, callback) {
var db = new sqlite3.Database('db/' + db_env + '.db');

var statement = "SELECT * FROM " + this.table_name + " ORDER BY " + column + " LIMIT ? OFFSET ?";

db.all(statement, queries, function(err, res) {
if (callback) { callback(err, res); }
db.close();
});
},

// Example route:
// customers/create/:name/:registered_at/:address/:city/:state/:postal_code/:phone
create: function(columns, values, callback) {
var db = new sqlite3.Database('db/' + db_env + '.db');
var column_names = columns.join(', ');
var question_marks = Array(columns.length + 1).join('?').split('').join(', ');

var statement = "INSERT INTO " + this.table_name + " (" + column_names + ") \
VALUES (" + question_marks + ");";

db.run(statement, values, function(err, res) {
if (callback) { callback(err, { inserted_id: this.lastID }); }
db.close();
});
},

// Example route:
// customers/update/:id?name=name&city=city&state=state
update: function(id, columns, values, callback) {
var db = new sqlite3.Database('db/' + db_env + '.db');
// eg. "column1 = ?, column2 = ?, column3 = ?"
var columnsQueries = [];

for (var i = 0; i < columns.length; i++) {
columnsQueries.push(columns[i] + " = ?");
};

var update_statement = columnsQueries.join(', ');

var statement = "UPDATE " + this.table_name + " SET " + update_statement + "WHERE id = " + id + ";";

db.run(statement, values, function(err, res) {
if (callback) { callback(err, { changes: this.changes }); }
db.close();
});
}
}
Binary file added db/development.db
Binary file not shown.
Binary file added db/test.db
Binary file not shown.
Loading