Download spectrum/api/migrations/20181001061156-thread-metadata-denormalization.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/migrations/20181001061156-thread-metadata-denormalization.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/migrations/20181001061156-thread-metadata-denormalization.js
-
curl -L -o 20181001061156-thread-metadata-denormalization.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/migrations/20181001061156-thread-metadata-denormalization.js
1.2 kB
| exports.up = function(r, conn) { | |
| return r | |
| .table('threads') | |
| .update( | |
| { | |
| messageCount: r | |
| .table('messages') | |
| .getAll(r.row('id'), { index: 'threadId' }) | |
| .count() | |
| .default(0), | |
| reactionCount: r | |
| .table('threadReactions') | |
| .getAll(r.row('id'), { index: 'threadId' }) | |
| .count() | |
| .default(0), | |
| }, | |
| { | |
| nonAtomic: true, | |
| } | |
| ) | |
| .run(conn) | |
| .then(() => { | |
| return Promise.all([ | |
| r | |
| .table('threads') | |
| .indexCreate('messageCount') | |
| .run(conn), | |
| r | |
| .table('threads') | |
| .indexCreate('reactionCount') | |
| .run(conn), | |
| ]); | |
| }) | |
| .catch(err => console.error(err)); | |
| }; | |
| exports.down = function(r, conn) { | |
| return r | |
| .table('threads') | |
| .update({ | |
| messageCount: r.literal(), | |
| reactionCount: r.literal(), | |
| }) | |
| .run(conn) | |
| .then(() => { | |
| return Promise.all([ | |
| r | |
| .table('threads') | |
| .indexDrop('messageCount') | |
| .run(conn), | |
| r | |
| .table('threads') | |
| .indexDrop('reactionCount') | |
| .run(conn), | |
| ]); | |
| }); | |
| }; | |