Simple alteration to node-mbtiles allowing for storing mbtiles in a postgres database, gutted for readability. you must use https://github.com/jaredbrookswhite/tilelive-vector for compatibility with tilelive-vector based mapbox builds.
npm install mbtiles
// call connection once and store in global variable
// connection info can be found with the npm pg package
new pgtiles({
connection: {
"user": "username",
"password": "yourpassword",
"database": "yourdb",
"port": 5432,
"host": "path/to/host",
"ssl": true
},
query: { batch: 1 }
}, function(err, pgtiles) {
if (err) return err;
tm.pgtiles = pgtiles;
});
//storage schema is simplified, use gettile and puttile as such,
//m stands for map name and stores all records on a single table...
//optimal for speed, no, but great for simplicity.
pgtiles.gettile(m,z,x,y,callback);
pgtiles.puttile(m,z,x,y,callback);