jameslaneconkling / falcor-sql-router Goto Github PK
View Code? Open in Web Editor NEWExpress routes to map falcor requests to SQL queries. Built on SQLite, Express, Falcor, with a simple web client and comprehensive test suite.
Express routes to map falcor requests to SQL queries. Built on SQLite, Express, Falcor, with a simple web client and comprehensive test suite.
...research?
which is true, unless we add filters on nodeCollections
{
"jsonGraph": {
"foldersById": {
"1": {
"id": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
},
"name": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
},
"parentId": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
}
},
"3": {
"id": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
},
"name": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
},
"parentId": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
}
},
"5": {
"id": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
},
"name": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
},
"parentId": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
}
},
"15": {
"id": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
},
"name": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
},
"parentId": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
}
}
}
}
}
might be more efficient to report on every object, rather than every object field. e.g.
{
"jsonGraph": {
"foldersById": {
"1": {
"$type": "error",
"value": {
"message": "SQLITE_ERROR: near \"SSELECT\": syntax error"
}
}
}
}
}
{
route: 'foldersById[{keys:ids}].folders.createSubFolder',
call(callPath, args, refPaths, thisPaths) {
const ids = callPath.ids;
const name = args[0].name;
return Rx.Observable.from(ids)
.concatMap(id => {
// create folder
// TODO - how to better create two observables in sequence (second is created only after the first completes) and combine their results
return Folder.create(name, id)
.flatMap(folder => {
// get new count of parent folder's subfolders
return Folder.getSubfolderCount(id)
.map(data => Object.assign(folder, {parentSubFolderCount: data.count}));
});
})
.map(folder => {
// return pathValue ref linking parentFolder to new folder
// TODO - this assumes the new folder is inserted at the end of the parentFolder.folders list
const folderPathValue = {
path: ['foldersById', folder.parentId, 'folders', folder.parentSubFolderCount -1],
value: $ref(['foldersById', folder.id])
};
return [folderPathValue];
// return pathValues for refPaths, if known
// TODO - this doesn't actually prevent a subsequent call to folderById.newFolderId[refPaths]
// though the equivalent jsonGraphEnvelope does...
// const folderFieldPathValues = refPaths
// .filter(path => path.length === 1 && ['id', 'name', 'parentId'].indexOf(path[0]) >= 0)
// .map(path => path[0])
// .map(field => ({
// path: ['foldersById', folder.parentId, 'folders', folder.parentSubFolderCount -1, field],
// value: folder[field]
// }));
// return [folderPathValue, ...folderFieldPathValues];
// TODO - thought hardcoded, this does prevent a subsequent call to folderById.newFolderId[refPaths]
// const jsonGraphEnvelope = {
// jsonGraph: {
// foldersById: {
// 1: {
// folders: {
// length: folder.parentSubFolderCount,
// 3: $ref(['foldersById', 10])
// }
// },
// 10: {id: folder.id, parentId: folder.parentId, name: folder.name}
// }
// },
// paths: [
// ['foldersById', 1, 'folders', 'length'],
// ['foldersById', 1, 'folders', folder.parentSubFolderCount -1, 'id'],
// ['foldersById', 1, 'folders', folder.parentSubFolderCount -1, 'parentId'],
// ['foldersById', 1, 'folders', folder.parentSubFolderCount -1, 'name']
// ],
// invalidated: [[]]
// };
// return jsonGraphEnvelope;
});
exports.getByIds = (ids, fields) => {
return Rx.Observable.create(observer => {
// this error is properly handled
throw new Error('ERERERERERE')
db.all(`SELECT id, ${fields.join(', ')} FROM folder WHERE id IN (${ids.join(', ')})`, [], (err, rows) => {
if (err) {
// this error is of course properly handled
observer.onError(err);
} else {
// this error is not properly handled
throw new Error('HEREHERE');
observer.onCompleted();
}
});
});
};
On not properly handled error, app crashes, rather than causing Observable to emit an error
and return on the field, when they arguably should return on the object
{
"jsonGraph": {
"foldersById": {
"1": {
"id": {
"$type": "error",
"value": {}
},
"name": {
"$type": "error",
"value": {}
},
"parentId": {
"$type": "error",
"value": {}
}
},
"3": {
"id": {
"$type": "error",
"value": {}
},
"name": {
"$type": "error",
"value": {}
},
"parentId": {
"$type": "error",
"value": {}
}
}
}
}
}
GET [list[0]['goodField', 'badField']]
should return
{
list: {
0: {
goodField: value,
badField: { $type: 'error', message: 'badField does not exist' }
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.