Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Switched example back to NeDB.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyystop committed Feb 4, 2018
1 parent 426c462 commit b52d714
Show file tree
Hide file tree
Showing 31 changed files with 93 additions and 183 deletions.
3 changes: 1 addition & 2 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"default": 10,
"max": 50
},
"nedb": "../data",
"mongodb": "mongodb://localhost:27017/cli_generator_example"
"nedb": "../data"
}
9 changes: 2 additions & 7 deletions feathers-gen-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"comment": {
"name": "comment",
"fileName": "comment",
"adapter": "mongodb",
"adapter": "nedb",
"path": "/comment",
"requiresAuth": false,
"graphql": true,
Expand Down Expand Up @@ -58,17 +58,12 @@
"database": "nedb",
"adapter": "nedb",
"connectionString": "../data"
},
"mongodb+mongodb": {
"database": "mongodb",
"adapter": "mongodb",
"connectionString": "mongodb://localhost:27017/cli_generator_example"
}
},
"graphql": {
"name": "graphql",
"path": "graphql",
"strategy": "batchloaders",
"strategy": "services",
"requiresAuth": false
}
}
2 changes: 1 addition & 1 deletion public/serverUrl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// URL of server
var serverUrl = 'http://192.168.1.130:3030'; // eslint-disable-line
var serverUrl = 'http://192.168.2.111:3030'; // eslint-disable-line
console.warn('You probably need to change the URL in /public/serverUrl.js, likely to localhost:3030');
// var serverUrl = 'localhost:3030'; // eslint-disable-line
3 changes: 0 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const services = require('./services');
const appHooks = require('./app.hooks');
const channels = require('./channels');

const mongodb = require('./mongodb');
//!code: imports //!end
//!code: init //!end

Expand All @@ -42,8 +41,6 @@ app.use('/', express.static(app.get('public')));
app.configure(express.rest());
app.configure(socketio());

// Configure database adapters
app.configure(mongodb);

// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
Expand Down
19 changes: 3 additions & 16 deletions src/services/comment/comment.hooks.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@

// Hooks for service `comment`. (Can be re-generated.)
const commonHooks = require('feathers-hooks-common');
const { ObjectID } = require('mongodb');
//!code: imports //!end

//!<DEFAULT> code: used
// eslint-disable-next-line no-unused-vars
const { iff, mongoKeys } = commonHooks;
//!end
//!<DEFAULT> code: foreign_keys
// eslint-disable-next-line no-unused-vars
const foreignKeys = [
"id",
"_id",
"uuid",
"authorUuid",
"postUuid",
"xx.b"
];
const { iff } = commonHooks;
//!end

//!code: init //!end

let moduleExports = {
before: {
// Your hooks should include:
// find: mongoKeys(ObjectID, foreignKeys)
//!<DEFAULT> code: before
all: [],
find: [ mongoKeys(ObjectID, foreignKeys) ],
find: [],
get: [],
create: [],
update: [],
Expand Down
21 changes: 3 additions & 18 deletions src/services/comment/comment.mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,19 @@ let moduleExports = deepMerge.all([{},
required: [],
properties: {
uuid: {
bsonType: "string"
bsonType: "integer"
},
authorUuid: {
bsonType: "string"
bsonType: "integer"
},
postUuid: {
bsonType: "string"
bsonType: "integer"
},
body: {
bsonType: "string"
},
archived: {
bsonType: "integer"
},
xx: {
bsonType: "object",
required: undefined,
properties: {
a: {
bsonType: "string"
},
b: {
bsonType: "string"
}
}
},
yy: {
bsonType: "array"
}
}
},
Expand Down
15 changes: 4 additions & 11 deletions src/services/comment/comment.mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@ const mongoose = require('mongoose');
let moduleExports = deepMerge.all([{},
//!<DEFAULT> code: model
{
uuid: mongoose.Schema.ObjectId,
authorUuid: mongoose.Schema.ObjectId,
postUuid: mongoose.Schema.ObjectId,
uuid: Number,
authorUuid: Number,
postUuid: Number,
body: String,
archived: Number,
xx: {
a: String,
b: mongoose.Schema.ObjectId
},
yy: [
String
]
archived: Number
},
//!end
//!code: moduleExports //!end
Expand Down
21 changes: 4 additions & 17 deletions src/services/comment/comment.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,11 @@ let schema = {
//!code: schema_properties
id: { type: 'ID' },
_id: { $ref: '#/definitions/id' },
uuid: { type: 'ID' },
authorUuid: { type: 'ID' },
postUuid: { type: 'ID' },
uuid: { type: 'integer' },
authorUuid: { type: 'integer' },
postUuid: { type: 'integer' },
body: { $ref: 'body.json' },
archived: { type: 'integer' },
xx: {
properties: {
a: {},
b: { type: 'ID' }
}
},
yy: {
"type": "array",
"items": [
{ "type": "ID" },
{ "type": "ID" }
]
}
archived: { type: 'integer' }
//!end
},
//!code: schema_more //!end
Expand Down
36 changes: 15 additions & 21 deletions src/services/comment/comment.service.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@

// Initializes the `comment` service on path `/comment`
const createService = require('feathers-mongodb');
// Initializes the `comment` service on path `/comment`. (Can be re-generated.)
const createService = require('feathers-nedb');
const createModel = require('../../models/comment.model');
const hooks = require('./comment.hooks');
//!code: mongo_imports //!end
//!code: mongo_init //!end

let moduleExports = function (app) {
let paginate = app.get('paginate');
let mongoClient = app.get('mongoClient');
let options = { paginate };
//!code: mongo_func_init //!end
module.exports = function (app) {
const Model = createModel(app);
const paginate = app.get('paginate');

const options = {
name: 'comment',
Model,
paginate,
//!code: options_more
id: 'uuid',
//!end
};

// Initialize our service with any options it requires
app.use('/comment', createService(options));

// Get our initialized service so that we can register hooks and filters
const service = app.service('comment');

mongoClient.then(db => {
service.Model = db.collection('comment');
});

service.hooks(hooks);
//!code: mongo_func_return //!end
};
//!code: mongo_more //!end

//!code: mongo_exports //!end
module.exports = moduleExports;

//!code: mongo_funcs //!end
//!code: mongo_end //!end
28 changes: 3 additions & 25 deletions src/services/comment/comment.validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const base = deepMerge.all([{},
readOnly: true
},
uuid: {
type: ID
type: "integer"
},
authorUuid: {
type: ID
type: "integer"
},
postUuid: {
type: ID
type: "integer"
},
body: {
description: "body of posting or comment",
Expand All @@ -45,28 +45,6 @@ const base = deepMerge.all([{},
},
archived: {
type: "integer"
},
xx: {
properties: {
a: {
type: "string"
},
b: {
type: ID
}
},
type: "object"
},
yy: {
type: "array",
items: [
{
type: "string"
},
{
type: ID
}
]
}
}
},
Expand Down
29 changes: 12 additions & 17 deletions src/services/graphql/graphql.schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,30 @@ let moduleExports = `
type Comment {
id: ID
_id: ID
uuid: ID
authorUuid: ID
postUuid: ID
uuid: Int
authorUuid: Int
postUuid: Int
body: String
archived: Int
xx: {
a: String
b: ID
}
yy: [String]
author: User!
likes: [Like!]
}
type Like {
id: ID
_id: ID
uuid: ID
authorUuid: ID
commentUuid: ID
uuid: Int
authorUuid: Int
commentUuid: Int
author: User!
comment: Comment!
}
type Post {
id: ID
_id: ID
uuid: ID
authorUuid: ID
uuid: Int
authorUuid: Int
body: String
draft: Int
author: User!
Expand All @@ -45,17 +40,17 @@ type Post {
type Relationship {
id: ID
_id: ID
uuid: ID
followerUuid: ID
followeeUuid: ID
uuid: Int
followerUuid: Int
followeeUuid: Int
follower: User!
followee: User!
}
type User {
id: ID
_id: ID
uuid: ID!
uuid: Int!
email: String!
firstName: String!
lastName: String!
Expand Down
8 changes: 4 additions & 4 deletions src/services/graphql/graphql.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const createService = require('@feathers-plus/graphql');
const { mergeTypes } = require('merge-graphql-schemas');
const deepMerge = require('deepmerge');
const generatedSchema = require('./graphql.schemas');
const generatedResolvers = require('./batchloader.resolvers');
const generatedResolvers = require('./service.resolvers');
const hooks = require('./graphql.hooks');
//!code: imports //!end

const strategy = 'batchloaders';
const strategy = 'services';
// eslint-disable-next-line no-console
console.log(`\n===== configuring graphql service for ${strategy}.\n`);

Expand All @@ -19,7 +19,7 @@ let schemas = mergeTypes([

let resolvers = (app, options) => deepMerge.all([{},
generatedResolvers(app, options),
//!code: batchloader_resolvers //!end
//!code: service_resolvers //!end
]);
//!code: init //!end

Expand Down Expand Up @@ -52,7 +52,7 @@ module.exports = moduleExports;

/*
Stash code not used now but which may be used if the module is regenerated.
//!code: service_resolvers //!end
//!code: batchloader_resolvers //!end
//!code: sql_resolvers //!end
//!code: sql_metadata //!end
*/
6 changes: 3 additions & 3 deletions src/services/like/like.mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ let moduleExports = deepMerge.all([{},
required: [],
properties: {
uuid: {
bsonType: "string"
bsonType: "integer"
},
authorUuid: {
bsonType: "string"
bsonType: "integer"
},
commentUuid: {
bsonType: "string"
bsonType: "integer"
}
}
},
Expand Down
Loading

0 comments on commit b52d714

Please sign in to comment.