https://github.com/ethiclab/crud-git
Git implementation of crud-mongo (https://github.com/ethiclab/crud-mongo)
https://github.com/ethiclab/crud-git
Last synced: 2 months ago
JSON representation
Git implementation of crud-mongo (https://github.com/ethiclab/crud-mongo)
- Host: GitHub
- URL: https://github.com/ethiclab/crud-git
- Owner: ethiclab
- Created: 2020-10-07T14:46:19.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-21T16:42:29.000Z (over 5 years ago)
- Last Synced: 2025-06-03T22:02:01.784Z (about 1 year ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# crud-git
npm install @ethiclab/crud-git
# status
Development in progress.
# usage
A simple example, with no actual express router, only for testing purposes.
```javascript
const crud = require("@ethiclab/crud-git");
(async () => {
const controller = await crud({
url: 'https://github.com/ethiclab/samplegitdb.git',
databaseName: 'sys',
root: '/',
router: {
get: () => {
return {}
},
post: () => {
return {}
},
put: () => {
return {}
},
delete: () => {
return {}
}
},
col: 'mycollection'
})
const x = await controller.create({
name: 'test object'
})
console.log(x)
})()
```
The property databaseName refers to a folder in the repository.
Behaviour depends on the kind of the filesystem file 'mycollection'
1. If it is a folder, then items are also folders named with a key (TODO: how to generate the key?)
2. In case of a text file, the items are the single rows of that file.
An example using express router.
```javascript
const crud = require("@ethiclab/crud-git");
const express = require('express')
const app = express()
const router = express.Router()
crud({
url: 'https://github.com/ethiclab/samplegitdb.git',
databaseName: 'sys',
root: '/',
router: router,
col: 'mycollection'
})
app.use((req, res, next) => {
router(req, res, next)
})
app.listen(12345)
```
Then, you can visit:
http://localhost:12345/mycollection
You can also use, for instance, Postman, for creating, updating and deleting records.
The following endpoints are defined:
GET /mycollection
POST /mycollection
GET /mycollection/:id
PUT /mycollection/:id
DELETE /mycollection/:id
# where are the schemas?
This is a low level library for storing arbitrary documents with arbitrary properties
in order to support new properties, therefore, we decided not to add schema support
at this level.
# test
GITHUB_TOKEN= npm test
# test server
node test/server.js