-
-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added generators for feathers-objection & feathers-cassandra (#…
- Loading branch information
Showing
14 changed files
with
9,062 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/generator-feathers/generators/connection/templates/cassandra.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const ExpressCassandra = require('express-cassandra'); | ||
const FeathersCassandra = require('feathers-cassandra'); | ||
|
||
module.exports = function (app) { | ||
const connectionInfo = app.get('<%= database %>'); | ||
const models = ExpressCassandra.createClient(connectionInfo); | ||
const cassandraClient = models.orm.get_system_client(); | ||
|
||
app.set('models', models); | ||
|
||
cassandraClient.connect(err => { | ||
if (err) throw err; | ||
|
||
const cassanknex = require('cassanknex')({ connection: cassandraClient }); | ||
|
||
FeathersCassandra.cassanknex(cassanknex); | ||
|
||
cassanknex.on('ready', err => { | ||
if (err) throw err; | ||
}); | ||
|
||
app.set('cassanknex', cassanknex); | ||
}); | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages/generator-feathers/generators/connection/templates/objection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { Model } = require('objection'); | ||
|
||
module.exports = function (app) { | ||
const { client, connection } = app.get('<%= database %>'); | ||
const knex = require('knex')({ client, connection, useNullAsDefault: false }); | ||
|
||
Model.knex(knex); | ||
|
||
app.set('knex', knex); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/generator-feathers/generators/service/templates/model/cassandra-user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// See https://express-cassandra.readthedocs.io/en/latest/schema/ | ||
// for more of what you can do here. | ||
module.exports = function (app) { | ||
const models = app.get('models'); | ||
const <%= camelName %> = models.loadSchema('<%= camelName %>', { | ||
table_name: '<%= snakeName %>', | ||
fields: { | ||
id: 'int', | ||
<% if(authentication.strategies.indexOf('local') !== -1) { %> | ||
email: 'text', | ||
password: { | ||
type: 'text', | ||
rule: { | ||
required: true | ||
} | ||
}, | ||
<% } %><% authentication.oauthProviders.forEach(provider => { %> | ||
<%= provider.name %>Id: 'text', | ||
<% }); %> | ||
}, | ||
key: ['id'], | ||
custom_indexes: [ | ||
{ | ||
on: 'email', | ||
using: 'org.apache.cassandra.index.sasi.SASIIndex', | ||
options: {} | ||
}, | ||
{ | ||
on: 'password', | ||
using: 'org.apache.cassandra.index.sasi.SASIIndex', | ||
options: {} | ||
} | ||
], | ||
options: { | ||
timestamps: true | ||
} | ||
}, function (err) { | ||
if (err) throw err; | ||
}); | ||
|
||
<%= camelName %>.syncDB(function (err) { | ||
if (err) throw err; | ||
}); | ||
|
||
return <%= camelName %>; | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/generator-feathers/generators/service/templates/model/cassandra.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// See https://express-cassandra.readthedocs.io/en/latest/schema/ | ||
// for more of what you can do here. | ||
module.exports = function (app) { | ||
const models = app.get('models'); | ||
const <%= camelName %> = models.loadSchema('<%= camelName %>', { | ||
table_name: '<%= snakeName %>', | ||
fields: { | ||
id: 'int', | ||
text: { | ||
type: 'text', | ||
rule: { | ||
required: true | ||
} | ||
} | ||
}, | ||
key: ['id'], | ||
custom_indexes: [ | ||
{ | ||
on: 'text', | ||
using: 'org.apache.cassandra.index.sasi.SASIIndex', | ||
options: {} | ||
} | ||
], | ||
options: { | ||
timestamps: true | ||
} | ||
}, function (err) { | ||
if (err) throw err; | ||
}); | ||
|
||
<%= camelName %>.syncDB(function (err) { | ||
if (err) throw err; | ||
}); | ||
|
||
return <%= camelName %>; | ||
}; |
60 changes: 60 additions & 0 deletions
60
packages/generator-feathers/generators/service/templates/model/objection-user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// See https://vincit.github.io/objection.js/#models | ||
// for more of what you can do here. | ||
const { Model } = require('objection'); | ||
|
||
class <%= camelName %> extends Model { | ||
|
||
static get tableName() { | ||
return '<%= snakeName %>'; | ||
} | ||
|
||
static get jsonSchema() { | ||
return { | ||
type: 'object', | ||
required: ['password'], | ||
|
||
properties: { | ||
<% if(authentication.strategies.indexOf('local') !== -1) { %> | ||
email: { type: ['string', 'null'] }, | ||
password: 'string', | ||
<% } %><% authentication.oauthProviders.forEach(provider => { %> | ||
<%= provider.name %>Id: { type: 'string' }, | ||
<% }); %> | ||
} | ||
}; | ||
} | ||
|
||
$beforeInsert() { | ||
this.createdAt = this.updatedAt = new Date().toISOString(); | ||
} | ||
|
||
$beforeUpdate() { | ||
this.updatedAt = new Date().toISOString(); | ||
} | ||
} | ||
|
||
module.exports = function (app) { | ||
const db = app.get('knex'); | ||
|
||
db.schema.hasTable('<%= snakeName %>').then(exists => { | ||
if (!exists) { | ||
db.schema.createTable('<%= snakeName %>', table => { | ||
table.increments('id'); | ||
<% if(authentication.strategies.indexOf('local') !== -1) { %> | ||
table.string('email').unique(); | ||
table.string('password'); | ||
<% } %> | ||
<% authentication.oauthProviders.forEach(provider => { %> | ||
table.string('<%= provider.name %>Id'); | ||
<% }); %> | ||
table.timestamp('createdAt'); | ||
table.timestamp('updatedAt'); | ||
}) | ||
.then(() => console.log('Created <%= snakeName %> table')) // eslint-disable-line no-console | ||
.catch(e => console.error('Error creating <%= snakeName %> table', e)); // eslint-disable-line no-console | ||
} | ||
}) | ||
.catch(e => console.error('Error creating <%= snakeName %> table', e)); // eslint-disable-line no-console | ||
|
||
return <%= camelName %>; | ||
}; |
Oops, something went wrong.