Home > Backend Development > Golang > How to Query Datastore for Prefixed Strings in Google App Engine?

How to Query Datastore for Prefixed Strings in Google App Engine?

Barbara Streisand
Release: 2024-10-24 07:04:02
Original
952 people have browsed it

How to Query Datastore for Prefixed Strings in Google App Engine?

Searching for Prefixed Strings in Google App Engine Datastore

Querying Google App Engine Datastore to retrieve entities based on a prefix can be achieved through a combination of inequality filters.

To search for all entities where the "Name" property begins with a specific string, use a GQL query as follows:

SELECT * FROM Places WHERE Name > 'prefix' AND Name < 'prefix' + '\xFF'
Copy after login

Alternatively, in Go code, the query can be expressed as:

q := datastore.NewQuery("Places").Filter("Name >", "prefix").Filter("Name <", "prefix" + "\xFF")
Copy after login

This approach ensures that the query retrieves only entities with names greater than (or equal to) the specified prefix and less than the lexicographically next string in sequence. For example, for the prefix "li," it will match names like "liam," "lisotto," and "lizst" but exclude names like "abc," "ljoi," or "qwerty."

Note that the query is case-sensitive, meaning that "List" and "li" are considered distinct values in the lexicographical ordering.

The above is the detailed content of How to Query Datastore for Prefixed Strings in Google App Engine?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template