Common Patterns

As with most software packages and libraries there are common patterns that are used most of the time, with some functionality used in edge cases (I've thought a lot about this as it pertains to external libraries in software engineering and my best guess is that it follows a Pareto-like cumulative distribution). The point of this chapter is to lay out the most common patterns used. More advanced topics such as validations, callbacks, and tests are addressed in their own chapter.

Connecting to a Database

Creating New Records

Querying for One Record by ID

Querying for All Records

Querying for Certain Data

Updating Single Records

Updating Multiple Records

Deleting Single Records

Deleting Multiple Records

For all the example patterns we'll be using the User model created in the quick start section using the development database. The examples will also live in a file called main.go.

results matching ""

    No results matching ""