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

Closed
yspreen opened this issue Sep 13, 2024 · 6 comments
Closed

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

yspreen opened this issue Sep 13, 2024 · 6 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!

groue added a commit that referenced this issue Oct 12, 2024
@groue
Copy link
Owner

groue commented Oct 12, 2024

Hello @yspreen,

The overview of the schema features will be restored in the DocC documentation hosted on https://swiftpackageindex.com/groue/GRDB.swift/: #1652. It will bring the indexes overview that you have been missing.

groue added a commit that referenced this issue Oct 13, 2024
@groue groue closed this as completed in 13b6c9d Oct 13, 2024
@groue
Copy link
Owner

groue commented Oct 14, 2024

There we are. I restored the overview of possible schema changes at https://swiftpackageindex.com/groue/grdb.swift/v7.0.0-beta.6/documentation/grdb/databaseschemamodifications

This won't go in the main README, because DocC is the correct location for an ever-growing documentation. If you think the README should do better for helping people discover this documentation page, please suggest an improvement in a pull request.

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

No branches or pull requests

2 participants