1.0.31 • Published 6 years ago

gitlab-json-db v1.0.31

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

gitlab repository as a read/write json-database for the browser (using pipeline triggers)

Usage

  1. Initialize
$ npm install gitlab-json-db -g
$ mkdir mysite
$ cd mysite
$ git init
$ gdb init
created .gitlab-ci.yml + bin-files + gldb.js

Now us it like this:

		<script src="https://YOURORG.gitlab.io/YOURPROJECT/gldb.js"></script>
		<script>
				var db = gldb({
						trigger: "YOUR_GITLAB_PIPELINE_TRIGGER_URL",
						token: "YOUR_TOKEN",
						url: "https://YOURORG.gitlab.io/YOURPROJECT"
				})
				db.fruits = db.collection("fruits") 
				db.fruits.post({"apple":2}, alert, console.error)
		</script>
  1. Viola, we have our necessary files:
$ ls
bin/config.sh
bin/put
bin/post
bin/delete
gldb.js
.gitlab-ci.yml

Now edit bin/config.sh to define collection-to-repositories mappings (for example fruits points to git@gitlab.com:MYORG/fruits.git)

  1. Lets upload them:
$ git add .
$ git commit -m "1st commit"
$ git push origin master

Trigger & Deploy key

  1. Almost there. Now create a trigger in gitlab, to use the snippet mentioned in the pipeline output above
  1. Now on the database-repository(s) configure a new deploy key, and copy/paste the private value of the keyfile (not .pub) into the (gldb inited) repository:
  1. Also create an environment 'SSH_PRIVATE_KEY'-variable, and copy/paste the private value of the keyfile in there

Now the (gldb inited) has read/write access to your database repositorie(s). Check the pipeline output to verify this.

Done! Please check the previous steps in case things don't work. If things went fine: check the pipelines-log. A pipeline started to create a gitlab page (so gldb.js is accessible for the browser)

Reference

NOTE: all calls return a status (a pipeline is triggered), therefore it's not to be used for realtime output, but rather aftermath.

function callcomment
db.mycollection.post({"foo":"bar"}, cb, cb_err)will create item in /mycollection.json
db.mycollection.put({"id":"kjkj334$", "foo":"bar"}, cb, cb_err)will update item in /mycollection.json
db.mycollection.delete({"id":"kjkj334$""}, cb, cb_err)will delete item in /mycollection.json

NOTE: reading data is optional: you can expose your jsonfiles to the web by deploying database-repositories (A & B) as gitlab pages.

Why

  • microstack experiment
  • sometimes slow inserts/updates/deletions are good enough.

Pros/cons

  • pro: free, reliable hosting
  • con: writes are slow (so use your browsermemory as database e.g.)
1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.19

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago