Skip to content

Commit

Permalink
Delete sql instructions (GoogleCloudPlatform#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
fhinkel authored Mar 29, 2019
1 parent c46abde commit 171deb2
Show file tree
Hide file tree
Showing 63 changed files with 123 additions and 1,472 deletions.
7 changes: 0 additions & 7 deletions .kokoro/e2e-tests/cloudsql/2_structured_data.cfg

This file was deleted.

7 changes: 0 additions & 7 deletions .kokoro/e2e-tests/cloudsql/3_binary_data.cfg

This file was deleted.

7 changes: 0 additions & 7 deletions .kokoro/e2e-tests/cloudsql/4_auth.cfg

This file was deleted.

7 changes: 0 additions & 7 deletions .kokoro/e2e-tests/cloudsql/5_logging.cfg

This file was deleted.

7 changes: 0 additions & 7 deletions .kokoro/e2e-tests/cloudsql/6_pubsub.cfg

This file was deleted.

3 changes: 1 addition & 2 deletions 2-structured-data/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# 2 - Structured data

![Cloud SQL Build Status][ci-badge-cloudsql] ![Datastore Build Status][ci-badge-datastore]
![Datastore Build Status][ci-badge-datastore]

[ci-badge-datastore]: https://storage.googleapis.com/nodejs-getting-started-tests-badges/2-datastore.svg
[ci-badge-cloudsql]: https://storage.googleapis.com/nodejs-getting-started-tests-badges/2-cloudsql.svg

This folder contains the sample code for the [Structured data][step-2]
tutorial. Please refer to the tutorial for instructions on configuring, running,
Expand Down
15 changes: 6 additions & 9 deletions 2-structured-data/books/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

const express = require('express');
const bodyParser = require('body-parser');

function getModel() {
return require(`./model-${require('../config').get('DATA_BACKEND')}`);
}
const model = require('./model-datastore');

const router = express.Router();

Expand All @@ -31,7 +28,7 @@ router.use(bodyParser.json());
* Retrieve a page of books (up to ten at a time).
*/
router.get('/', (req, res, next) => {
getModel().list(10, req.query.pageToken, (err, entities, cursor) => {
model.list(10, req.query.pageToken, (err, entities, cursor) => {
if (err) {
next(err);
return;
Expand All @@ -49,7 +46,7 @@ router.get('/', (req, res, next) => {
* Create a new book.
*/
router.post('/', (req, res, next) => {
getModel().create(req.body, (err, entity) => {
model.create(req.body, (err, entity) => {
if (err) {
next(err);
return;
Expand All @@ -64,7 +61,7 @@ router.post('/', (req, res, next) => {
* Retrieve a book.
*/
router.get('/:book', (req, res, next) => {
getModel().read(req.params.book, (err, entity) => {
model.read(req.params.book, (err, entity) => {
if (err) {
next(err);
return;
Expand All @@ -79,7 +76,7 @@ router.get('/:book', (req, res, next) => {
* Update a book.
*/
router.put('/:book', (req, res, next) => {
getModel().update(req.params.book, req.body, (err, entity) => {
model.update(req.params.book, req.body, (err, entity) => {
if (err) {
next(err);
return;
Expand All @@ -94,7 +91,7 @@ router.put('/:book', (req, res, next) => {
* Delete a book.
*/
router.delete('/:book', (req, res, next) => {
getModel().delete(req.params.book, err => {
model.delete(req.params.book, err => {
if (err) {
next(err);
return;
Expand Down
17 changes: 7 additions & 10 deletions 2-structured-data/books/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

const express = require('express');
const bodyParser = require('body-parser');

function getModel() {
return require(`./model-${require('../config').get('DATA_BACKEND')}`);
}
const model = require('./model-datastore');

const router = express.Router();

Expand All @@ -37,7 +34,7 @@ router.use((req, res, next) => {
* Display a page of books (up to ten at a time).
*/
router.get('/', (req, res, next) => {
getModel().list(10, req.query.pageToken, (err, entities, cursor) => {
model.list(10, req.query.pageToken, (err, entities, cursor) => {
if (err) {
next(err);
return;
Expand Down Expand Up @@ -73,7 +70,7 @@ router.post('/add', (req, res, next) => {
const data = req.body;

// Save the data to the database.
getModel().create(data, (err, savedData) => {
model.create(data, (err, savedData) => {
if (err) {
next(err);
return;
Expand All @@ -89,7 +86,7 @@ router.post('/add', (req, res, next) => {
* Display a book for editing.
*/
router.get('/:book/edit', (req, res, next) => {
getModel().read(req.params.book, (err, entity) => {
model.read(req.params.book, (err, entity) => {
if (err) {
next(err);
return;
Expand All @@ -109,7 +106,7 @@ router.get('/:book/edit', (req, res, next) => {
router.post('/:book/edit', (req, res, next) => {
const data = req.body;

getModel().update(req.params.book, data, (err, savedData) => {
model.update(req.params.book, data, (err, savedData) => {
if (err) {
next(err);
return;
Expand All @@ -124,7 +121,7 @@ router.post('/:book/edit', (req, res, next) => {
* Display a book.
*/
router.get('/:book', (req, res, next) => {
getModel().read(req.params.book, (err, entity) => {
model.read(req.params.book, (err, entity) => {
if (err) {
next(err);
return;
Expand All @@ -141,7 +138,7 @@ router.get('/:book', (req, res, next) => {
* Delete a book.
*/
router.get('/:book/delete', (req, res, next) => {
getModel().delete(req.params.book, err => {
model.delete(req.params.book, err => {
if (err) {
next(err);
return;
Expand Down
160 changes: 0 additions & 160 deletions 2-structured-data/books/model-cloudsql.js

This file was deleted.

34 changes: 1 addition & 33 deletions 2-structured-data/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,10 @@ nconf
// 1. Command-line arguments
.argv()
// 2. Environment variables
.env([
'DATA_BACKEND',
'INSTANCE_CONNECTION_NAME',
'MYSQL_USER',
'MYSQL_PASSWORD',
'NODE_ENV',
'PORT',
])
.env(['NODE_ENV', 'PORT'])
// 3. Config file
.file({file: path.join(__dirname, 'config.json')})
// 4. Defaults
.defaults({
// dataBackend can be 'datastore' or 'cloudsql'. Be sure to
// configure the appropriate settings for each storage engine below.
// If you are unsure, use datastore as it requires no additional
// configuration.
DATA_BACKEND: 'datastore',

MYSQL_USER: '',
MYSQL_PASSWORD: '',

PORT: 8080,
});

if (nconf.get('DATA_BACKEND') === 'cloudsql') {
checkConfig('MYSQL_USER');
checkConfig('MYSQL_PASSWORD');
if (nconf.get('NODE_ENV') === 'production') {
checkConfig('INSTANCE_CONNECTION_NAME');
}
}

function checkConfig(setting) {
if (!nconf.get(setting)) {
throw new Error(
`You must set ${setting} as an environment variable or in config.json!`
);
}
}
Loading

0 comments on commit 171deb2

Please sign in to comment.