• 3/16

List All Tables/Collections in a Database

Once Open returns a sessvariable (which satisfies the db.Database interface), use the Collections method to get all the structures in the database:

collections, err := sess.Collections()
...

log.Printf("Collections in %q: %v", sess.Name(), collections)

The db.Database interface provides methods that work on both SQL and NoSQL databases. In light of this, the structures of both database types are referred to generally as ‘collections’ and no particular distinction is made between ‘tables’ and ‘collections’.

You can call different db.Database methods depending on the database type. For example, if you’re working with a SQL database, sess will also satisfy sqlbuilder.Database.

  • 3/16