-
Notifications
You must be signed in to change notification settings - Fork 6
/
0-intro.tpl.go
executable file
·85 lines (70 loc) · 3.08 KB
/
0-intro.tpl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//** This file was code generated by GoT. DO NOT EDIT. ***
package orm
import (
"context"
"io"
)
// DrawTemplate draws the content of the matching control's template file.
func (ctrl *IntroPanel) DrawTemplate(ctx context.Context, _w io.Writer) (err error) {
if _, err = io.WriteString(_w, `<h1>Introduction to the ORM</h1>
<p>
The Object-Relational Model, or ORM, is a code-generated package of structures and functions that make it possible
to access a variety of different kinds of databases using a common interface. The structures let you easily access
objects and member variables of objects, and also traverse relationships between objects.
</p>
<h2>Terminology</h2>
`); err != nil {
return
}
if _, err = io.WriteString(_w, `<p>
`); err != nil {
return
}
if _, err = io.WriteString(_w, `Different databases refer to data objects using different words, but the concepts are the same. For example,
in a SQL database a collection of objects corresponds to a "table" and a member variable in an object corresponds to a "field".
Each object in a table has a member variable which contains a unique key to identify that object, called the "primary key".
Relationships between two tables are defined using a "foreign key", which is essentially just a member variable in one
object that contains a copy of the primary key of a different object.
`); err != nil {
return
}
if _, err = io.WriteString(_w, `</p>
<p>
`); err != nil {
return
}
if _, err = io.WriteString(_w, `For example, if a "project" object wanted easy access to the "person" object that is the manager of the project,
the "project" object could have a member called "manager_id", which is the primary key of the "person" object
that contains information on the project's manager. Note that this sets up a one-to-many relationship, because
the project points to only one manager, but a manager might be managing multiple projects, and so will have multiple projects
pointing back to the manager.
This tutorial will teach you how to set up database relationships, and traverse them to create and retrieve the data you want.
If you have not yet set up the example database, do that now using the steps below.
`); err != nil {
return
}
if _, err = io.WriteString(_w, `</p>
<h2>Naming Conventions</h2>
<p>
When creating your database, name your tables and fields using snake_case, which means use all lower-case letters and
separate words with underscores. The reason for this is that some databases are not case-sensitive, and so Goradd has
adopted this convention to provide the maximum compatibility between different kinds of databases.
</p>
<p>
The Goradd ORM will convert snake_case names in the database to CamelCase names in Go code, meaning each name will capitalize the
start of each word.
</p>
<p>
`); err != nil {
return
}
if _, err = io.WriteString(_w, `For example, a field named "team_member" in the database will become "TeamMember" in Go.
`); err != nil {
return
}
if _, err = io.WriteString(_w, `</p>
`); err != nil {
return
}
return
}