func New(conf database.Config, m *mapping.Mapping) (database.DB, error) { db := &PostGIS{} db.Tables = make(map[string]*TableSpec) db.GeneralizedTables = make(map[string]*GeneralizedTableSpec) db.Config = conf if strings.HasPrefix(db.Config.ConnectionParams, "postgis://") { db.Config.ConnectionParams = strings.Replace( db.Config.ConnectionParams, "postgis", "postgres", 1, ) } params, err := pq.ParseURL(db.Config.ConnectionParams) if err != nil { return nil, err } params = disableDefaultSslOnLocalhost(params) db.Prefix = prefixFromConnectionParams(params) for name, table := range m.Tables { db.Tables[name] = NewTableSpec(db, table) } for name, table := range m.GeneralizedTables { db.GeneralizedTables[name] = NewGeneralizedTableSpec(db, table) } db.prepareGeneralizedTableSources() db.prepareGeneralizations() db.pointTagMatcher = m.PointMatcher() db.lineStringTagMatcher = m.LineStringMatcher() db.polygonTagMatcher = m.PolygonMatcher() db.Params = params err = db.Open() if err != nil { return nil, err } return db, nil }