Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating an index isn't documented in the main readme anymore #1623

Open
yspreen opened this issue Sep 13, 2024 · 4 comments
Open

Creating an index isn't documented in the main readme anymore #1623

yspreen opened this issue Sep 13, 2024 · 4 comments

Comments

@yspreen
Copy link

yspreen commented Sep 13, 2024

Links like the one in this post are now dead: https://forums.swift.org/t/how-to-add-an-index-for-a-column/48312

Would be nice to have an easily cmd+f'able headline right in the main readme. Other use-cases are explained there, like querying by index, I can't figure out how to create an index though.

@yspreen yspreen changed the title Creating a index isn't documented in the main readme anymore Creating an index isn't documented in the main readme anymore Sep 13, 2024
@groue
Copy link
Owner

groue commented Sep 13, 2024

Hello @yspreen,

The documentation about the database schema is available at https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/databaseschema

To create indexes, you can use one of the index creation methods, or profit from convenience apis:

try db.create(table: "player") { t in
    t.autoIncrementedPrimaryKey("id")

    // Creates an index or a unique index on the name column.
    t.column("name", .text).indexed()
    t.column("name", .text).unique()

    // Implicitly creates an index of the teamId foreign key.
    t.belongsTo("team")

    // Creates a unique index of the (a, b) columns.
    t.uniqueKey(["a", "b"])
}

@yspreen
Copy link
Author

yspreen commented Sep 13, 2024

I appreciate the answer. I think it might be beneficial to have a section in the main readme file for creating indexes, since there are sections in that file for querying them. it seems slightly inconsistent

@groue
Copy link
Owner

groue commented Sep 13, 2024

Do you have anything specific in mind? There are already sections about the schema in the main README.

@yspreen
Copy link
Author

yspreen commented Sep 13, 2024

I ended up using

try db.create(index: "index", on: "table", columns: ["column"], ifNotExists: true)

because I didn't know the .indexed convenience method was a thing. Might be useful to surface it with some searchable keywords (like "How to create an index") in the main readme. I would've greatly benefited from that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants