NodeBox

Create visual output with Python programming code
Home Download Reference Tutorial Library Gallery About

database.Database.index()

Syntax

index(table, field, unique=False, ascending=True)

Description

Indexes in a database makes things go faster: searching through an index of a million records is easier than going through the million records directly. The index() command creates an index on the given field in the given table. Table find() operations on this field will then run faster. The id-field of a table is automatically indexed when you create the table. When you define the unique parameter as True, the indexed field must be a unqiue value for each record in the table.

Example

To make searching on page titles go faster, the title field is indexed:

db = ximport("database")
book = db.create("book")
book.append("pages", ["title", "text", "image", "pagenumber"])
book.index("table", "title")