db connection

This commit is contained in:
BuckarooBanzay 2020-07-07 08:52:08 +02:00
parent f96e2f607d
commit 43cdf7dbf2
15 changed files with 219 additions and 0 deletions

1
dev/minetest.conf Normal file
View File

@ -0,0 +1 @@
default_privs = fast, home, fly, noclip, privs

9
dev/start-mt.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
docker run --rm -it \
-u root:root \
-v $(pwd)/minetest.conf:/data/minetest.conf \
-v $(pwd)/world.mt:/data/world/world.mt \
-v $(pwd)/worldmods:/data/world/worldmods \
--network host \
buckaroobanzay/minetest:5.2.0-r1

7
dev/start-pg.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
# setup
docker run --name mapcleaner_db --rm \
-e POSTGRES_PASSWORD=enter \
-p 5432:5432 \
postgres

2
dev/start-psql.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
docker exec -it mapcleaner_db psql -U postgres

10
dev/world.mt Normal file
View File

@ -0,0 +1,10 @@
gameid = minetest
creative_mode = false
enable_damage = true
pgsql_connection = host=127.0.0.1 port=5432 user=postgres password=enter dbname=postgres
pgsql_player_connection = host=127.0.0.1 port=5432 user=postgres password=enter dbname=postgres
auth_backend = sqlite3
player_backend = postgresql
backend = postgresql

View File

@ -0,0 +1,23 @@
local function execute_mapgen(callback)
local pos1 = { x=-50, y=-10, z=-50 }
local pos2 = { x=50, y=50, z=50 }
minetest.emerge_area(pos1, pos2, callback)
end
local function execute_test(callback)
execute_mapgen(function(blockpos, action, calls_remaining)
print("Emerged: " .. minetest.pos_to_string(blockpos))
if calls_remaining == 0 then
callback()
end
end)
end
minetest.register_on_mods_loaded(function()
minetest.after(1, function()
execute_test(function()
--TODO
end)
end)
end)

View File

@ -0,0 +1 @@
name = emerger

111
package-lock.json generated
View File

@ -129,6 +129,11 @@
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==",
"dev": true
},
"buffer-writer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz",
"integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw=="
},
"bytes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
@ -1070,6 +1075,11 @@
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
"dev": true
},
"packet-reader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
"integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ=="
},
"parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
@ -1092,12 +1102,90 @@
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"pg": {
"version": "8.2.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.2.1.tgz",
"integrity": "sha512-DKzffhpkWRr9jx7vKxA+ur79KG+SKw+PdjMb1IRhMiKI9zqYUGczwFprqy+5Veh/DCcFs1Y6V8lRLN5I1DlleQ==",
"requires": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "^2.2.3",
"pg-pool": "^3.2.1",
"pg-protocol": "^1.2.4",
"pg-types": "^2.1.0",
"pgpass": "1.x",
"semver": "4.3.2"
}
},
"pg-connection-string": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.2.3.tgz",
"integrity": "sha512-I/KCSQGmOrZx6sMHXkOs2MjddrYcqpza3Dtsy0AjIgBr/bZiPJRK9WhABXN1Uy1UDazRbi9gZEzO2sAhL5EqiQ=="
},
"pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
},
"pg-pool": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.2.1.tgz",
"integrity": "sha512-BQDPWUeKenVrMMDN9opfns/kZo4lxmSWhIqo+cSAF7+lfi9ZclQbr9vfnlNaPr8wYF3UYjm5X0yPAhbcgqNOdA=="
},
"pg-protocol": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.2.4.tgz",
"integrity": "sha512-/8L/G+vW/VhWjTGXpGh8XVkXOFx1ZDY+Yuz//Ab8CfjInzFkreI+fDG3WjCeSra7fIZwAFxzbGptNbm8xSXenw=="
},
"pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"requires": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
}
},
"pgpass": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
"requires": {
"split": "^1.0.0"
}
},
"picomatch": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz",
"integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==",
"dev": true
},
"postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA=="
},
"postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU="
},
"postgres-date": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.5.tgz",
"integrity": "sha512-pdau6GRPERdAYUQwkBnGKxEfPyhVZXG/JiS44iZWiNdSOWE09N2lUgN6yshuq6fVSon4Pm0VMXd1srUUkLe9iA=="
},
"postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"requires": {
"xtend": "^4.0.0"
}
},
"pq": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/pq/-/pq-0.0.3.tgz",
@ -1222,6 +1310,11 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"semver": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz",
"integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c="
},
"send": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz",
@ -1283,6 +1376,14 @@
"integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=",
"dev": true
},
"split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
"requires": {
"through": "2"
}
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
@ -1362,6 +1463,11 @@
}
}
},
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
@ -1475,6 +1581,11 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
},
"y18n": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",

View File

@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"jshint_backend": "cd src && jshint . && cd ../test/ && jshint .",
"start": "node src/index.js",
"test": "mocha"
},
"repository": {
@ -19,6 +20,7 @@
"homepage": "https://github.com/BuckarooBanzay/mapcleaner#readme",
"dependencies": {
"express": "^4.17.1",
"pg": "^8.2.1",
"pq": "0.0.3"
},
"devDependencies": {

5
public/index.html Normal file
View File

@ -0,0 +1,5 @@
<html>
<head>
<title>Mapcleaner</title>
</head>
</html>

6
src/app.js Normal file
View File

@ -0,0 +1,6 @@
const express = require('express');
const app = express();
app.use(express.static('public'));
module.exports = app;

6
src/events.js Normal file
View File

@ -0,0 +1,6 @@
const EventEmitter = require('events');
class MyEmitter extends EventEmitter {}
module.exports = new MyEmitter();

View File

@ -0,0 +1,22 @@
const app = require("./app");
const pool = require("./pool");
const port = process.env.PORT || 8080;
app.listen(+port, () => {
console.log(`Listening on http://127.0.0.1:${port}`);
});
pool.connect()
.then(client => {
return client.query(`select count(*) from blocks`)
.then(sql_res => {
console.log(sql_res);
client.release();
})
.catch(e => {
client.release();
console.error(e.stack);
});
});

5
src/pool.js Normal file
View File

@ -0,0 +1,5 @@
const { Pool } = require('pg');
const pool = new Pool();
module.exports = pool;

9
start-mapcleaner.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
export PGHOST=127.0.0.1
export PGUSER=postgres
export PGDATABASE=postgres
export PGPASSWORD=enter
export PGPORT=5432
npm start