Created
July 27, 2020 17:57
-
-
Save ericraio/8dc7ce0da8c92e4b5ee0dad297236c1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package publisherquerylanguage | |
import "golang.org/x/exp/errors/fmt" | |
func (pql *PublisherQueryLanguage) GetAllCountries() (*[]map[string]interface{}, error) { | |
query := `SELECT Id, CountryCode, CanonicalParentId, Name, Targetable, Type FROM Geo_Target WHERE Targetable='true' AND Type='Country' ORDER BY Name` | |
return pql.SearchWithStatement(query) | |
} | |
func (pql *PublisherQueryLanguage) GetAllStates() (*[]map[string]interface{}, error) { | |
query := `SELECT Id, CountryCode, CanonicalParentId, Name, Targetable, Type FROM Geo_Target WHERE Targetable='true' AND Type='State' ORDER BY Name` | |
return pql.SearchWithStatement(query) | |
} | |
// GetAllStatesByCountry will grab all the states for the country id passed in. | |
func (pql *PublisherQueryLanguage) GetAllStatesByCountry(countryID int) (*[]map[string]interface{}, error) { | |
query := fmt.Sprintf(`SELECT Id, CountryCode, CanonicalParentId, Name, Targetable, Type FROM Geo_Target WHERE Targetable='true' AND Type='State' AND CanonicalParentId = '%d' ORDER BY Name`, countryID) | |
return pql.SearchWithStatement(query) | |
} | |
func (pql *PublisherQueryLanguage) GetAllCities() (*[]map[string]interface{}, error) { | |
query := `SELECT Id, CountryCode, CanonicalParentId, Name, Targetable, Type FROM Geo_Target WHERE Targetable='true' AND Type='City' ORDER BY Name` | |
return pql.SearchWithStatement(query) | |
} | |
// GetAllCitiesByState will grab all the cities for the state id passed in. | |
func (pql *PublisherQueryLanguage) GetAllCitiesByState(stateID int) (*[]map[string]interface{}, error) { | |
query := fmt.Sprintf(`SELECT Id, CountryCode, CanonicalParentId, Name, Targetable, Type FROM Geo_Target WHERE Targetable='true' AND Type='City' AND CanonicalParentId = '%d' ORDER BY Name`, stateID) | |
return pql.SearchWithStatement(query) | |
} | |
// GetGeoTargetByParentID returns all the child geo target types for the parent id passed. | |
func (pql *PublisherQueryLanguage) GetGeoTargetByParentID(parentID int) (*[]map[string]interface{}, error) { | |
query := fmt.Sprintf(`SELECT Id, CountryCode, CanonicalParentId, Name, Targetable, Type FROM Geo_Target WHERE Targetable='true' AND CanonicalParentId = '%d' ORDER BY Name`, parentID) | |
return pql.SearchWithStatement(query) | |
} | |
// GetGeoTargetByParentIDAndType returns all the child geo target types for the parent id and type passed. | |
func (pql *PublisherQueryLanguage) GetGeoTargetByParentIDAndType(parentID int, geoType string) (*[]map[string]interface{}, error) { | |
query := fmt.Sprintf(`SELECT Id, CountryCode, CanonicalParentId, Name, Targetable, Type FROM Geo_Target WHERE Targetable='true' AND CanonicalParentId = '%d' AND Type='%s' ORDER BY Name`, parentID, geoType) | |
return pql.SearchWithStatement(query) | |
} | |
func (pql *PublisherQueryLanguage) GetGeoTargetByID(ID int) (*[]map[string]interface{}, error) { | |
query := fmt.Sprintf(`SELECT Id, CountryCode, CanonicalParentId, Name, Targetable, Type FROM Geo_Target WHERE Targetable='true' AND Id='%d' ORDER BY Name`, ID) | |
return pql.SearchWithStatement(query) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment