Coder Social home page Coder Social logo

postalex's Introduction

#Postalex

GenServer exposing services related to postal areas

Include as dependency

Via github

{:postalex, github: "ringling/postalex"}

or locally via path

git clone https://github.com/ringling/couchex {:postalex, path: "../postalex"}

Setup

The following environment variables are required

COUCH_SERVER_URL=<COUCH_SERVER_URL> #E.g https://couch.lokalebasen.dk
COUCH_USER=<USERNAME>
COUCH_PASS=<PASSWORD>

CouchDB

CouchDB databases must have the format {country}_{table_name} or {country}_{category}_{table_name}, depending on whether their content is category(sales, lease etc) specific. Examples

  • dk_postal_areas
  • se_postal_areas
  • dk_lease_locations
  • dk_sales_locations
  • se_lease_locations # PENDING
  • se_sales_locations # PENDING

CouchDB views

// Danish area => from dk_postal_areas database
{
	"_id": "bornholm",
	"_rev": "...",
	"type": "area",
	"id": "bornholm",
	"name": "Bornholm",
	"postal_districts": [
		{
			"type": "postal_district",
			"name": "Svaneke",
			"id": "3740-svaneke",
			"postal_codes": [
			   {
			       "postal_name": "Svaneke",
			       "postal_code": "3740",
			       "type": "postal_code"
			   }
			   ...
			]
		},
	...
// Swedish area => from se_postal_areas database
{
	"_id": "dalarna",
	"_rev": "...",
	"type": "area",
	"id": "dalarna",
	"name": "Dalarna",
	"postal_districts": [
		{
			"type": "postal_district",
			"name": "Malung-Sälen",
			"id": "malung-salen",
			"postal_codes": [
			  {
					"postal_name": "Hagfors",
					"postal_code": "68391",
					"type": "postal_code"
				}
				...
			]
		},

Required views

// {country}_postal_areas databases
{
   "_id": "_design/lists",
   "_rev": "7-684689ddbf6370bee370bb18c0382f59",
   "language": "javascript",
   "views": {
       "all": {
           "map": "function(doc) {\n  emit(doc.id, doc);\n}"
       },
       "postal_codes": {
           "map": "function(doc) {\n  pds = doc.postal_districts\n  for(i=0;i<pds.length;i++){\n    pcs = pds[i].postal_codes\n    for(j=0;j<pcs.length;j++){\n      data = { postal_name: pcs[j].postal_name, postal_code: pcs[j].postal_code, type: pcs[j].type, postal_district_id: pds[i].id}\n      emit(pcs[j].postal_code, data );\n    }\n  }\n}"
       },
       "postal_districts": {
           "map": "function(doc) {\n  pds = doc.postal_districts\n  for(i=0;i<pds.length;i++){\n    pd = pds[i]\n    emit(pd.id, {id: pd.id, name: pd.name, slug: pd.slug, key: pd.key } );\n  }\n}"
       }
   }
}

postalex's People

Contributors

omegahm avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.