Skip to content

Commit

Permalink
Support MySQL.
Browse files Browse the repository at this point in the history
  • Loading branch information
colekettler committed Sep 14, 2015
1 parent 1f8ccd4 commit aa460ff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
18 changes: 14 additions & 4 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ module.exports = AllYourBase.extend({
'Make sure you\'ve got it installed first, of course!',
choices: [
{ name: 'PostgreSQL', value: 'postgresql' },
{ name: 'MySQL', value: 'mysql' },
{ name: 'SQLite', value: 'sqlite' },
{ name: 'None / Other', value: 'none' }
],
Expand Down Expand Up @@ -318,16 +319,25 @@ module.exports = AllYourBase.extend({
python.pipInstall('psycopg2');
}

if (this.config.get('database') === 'mysql') {
python.pipInstall(
'mysql-connector-python',
['--allow-external', 'mysql-connector-python']
);
}

if (this.config.get('databaseMapper') === 'sqlalchemy') {
python.pipInstall(['flask-sqlalchemy', 'marshmallow-sqlalchemy']);
}

this.log(chalk.cyan('Writing requirements file...'));

this.fs.write(
this.destinationPath('requirements.txt'),
python.pipFreeze()
);
var requirements = python.pipFreeze();
if (this.config.get('database') === 'mysql') {
requirements = '--allow-external mysql-connector-python\n' +
requirements;
}
this.fs.write(this.destinationPath('requirements.txt'), requirements);
}
},

Expand Down
2 changes: 2 additions & 0 deletions generators/endpoint/templates/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<% if (databaseMapper === 'none') { -%>
<% if (database === 'postgresql') { -%>
import psycopg2
<% } else if (database === 'mysql') { -%>
import mysql.connector
<% } else if (database === 'sqlite') { -%>
import sqlite3

Expand Down
2 changes: 2 additions & 0 deletions generators/model/templates/object_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<% if (database === 'postgresql') { -%>
import psycopg2
<% } else if (database === 'mysql') { -%>
import mysql.connector
<% } else if (database === 'sqlite') { -%>
import sqlite3
<% } -%>
Expand Down
32 changes: 31 additions & 1 deletion test/test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,37 @@ describe('app with install', function () {
});
});

describe('app without database or mapper', function () {
describe('app with install with mysql', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../generators/app'))
.withOptions({ skipInstall: false })
.withPrompts({
database: 'mysql',
versioningScheme: 'none'
})
.on('ready', function () {
sandbox.stub(python, 'pipInstall');
sandbox.stub(python, 'pipFreeze').returns('');
sandbox.stub(python, 'whichPython');
sandbox.stub(python, 'whichPip');
sandbox.stub(python, 'inVirtualEnv').returns(true);
sandbox.stub(python, 'linkActiveVirtualEnv');
})
.on('end', done);
});

after(function () {
sandbox.restore();
});

it('creates a requirements file with external source', function () {
assert.fileContent(
'requirements.txt', /--allow-external mysql-connector-python/
);
});
});

describe('app with install without database or mapper', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../generators/app'))
.withOptions({ skipInstall: false })
Expand Down

0 comments on commit aa460ff

Please sign in to comment.