Skip to content

Commit c7275ad

Browse files
authored
add go sql reference docs and fix imported sql code for node (#670)
1 parent eaf0d24 commit c7275ad

File tree

5 files changed

+147
-12
lines changed

5 files changed

+147
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
description: "Reference for Nitric's Go library - Returns the connection string for a SQL database at runtime."
3+
---
4+
5+
# Go - SqlDatabase.ConnectionString()
6+
7+
Returns the connection string for a SQL database at runtime.
8+
9+
```go
10+
import (
11+
"context"
12+
13+
"github.com/nitrictech/go-sdk/nitric"
14+
)
15+
16+
func main() {
17+
db := nitric.NewSqlDatabase("my-database")
18+
19+
// Should be called at runtime, such as in a service handler
20+
connStr, _ := db.ConnectionString(context.TODO())
21+
22+
nitric.Run()
23+
}
24+
```
25+
26+
## Examples
27+
28+
### Return a connection string
29+
30+
```go
31+
import (
32+
"context"
33+
34+
"github.com/nitrictech/go-sdk/nitric"
35+
)
36+
37+
func main() {
38+
db := nitric.NewSqlDatabase("my-database")
39+
40+
// Should be called at runtime, such as in a service handler
41+
connStr, _ := db.ConnectionString(context.TODO())
42+
43+
nitric.Run()
44+
}
45+
```

docs/reference/go/sql/sql.mdx

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
description: "Reference for Nitric's Go library - Creates a reference to a SQL database."
3+
---
4+
5+
# Go - NewSqlDatabase()
6+
7+
Creates a reference to a SQL database.
8+
9+
```go
10+
import (
11+
"github.com/nitrictech/go-sdk/nitric"
12+
)
13+
14+
db := nitric.NewSqlDatabase("my-database")
15+
```
16+
17+
## Parameters
18+
19+
<Properties>
20+
<Property name="name" required type="string">
21+
The unique name of this database within the project.
22+
</Property>
23+
<Property name="options" type="...sqlDatabaseOption">
24+
Additional options for the SQL Database. See below.
25+
</Property>
26+
</Properties>
27+
28+
### SQL Database options
29+
30+
<Properties>
31+
<Property name="WithMigrationsPath()" type="sqlDatabaseOption">
32+
<Properties nested>
33+
<Property name="path" required type="string">
34+
Points to the location of migration files, prefixed with `file://`, or a
35+
migration dockerfile, prefixed with `dockerfile://`.
36+
</Property>
37+
</Properties>
38+
</Property>
39+
</Properties>
40+
41+
## Examples
42+
43+
### Create a reference to a database
44+
45+
```go
46+
import (
47+
"github.com/nitrictech/go-sdk/nitric"
48+
)
49+
50+
db := nitric.NewSqlDatabase("my-database")
51+
```
52+
53+
### With a migrations directory
54+
55+
```go
56+
import (
57+
"github.com/nitrictech/go-sdk/nitric"
58+
"github.com/nitrictech/go-sdk/nitric/sql"
59+
)
60+
61+
func main() {
62+
db := nitric.NewSqlDatabase("my-database", sql.WithMigrationsPath("file://migrations/my-database"))
63+
64+
nitric.Run()
65+
}
66+
```
67+
68+
### With a migrations dockerfile
69+
70+
```go
71+
import (
72+
"github.com/nitrictech/go-sdk/nitric"
73+
"github.com/nitrictech/go-sdk/nitric/sql"
74+
)
75+
76+
func main() {
77+
db := nitric.NewSqlDatabase("my-database", sql.WithMigrationsPath("dockerfile://migrations.dockerfile"))
78+
79+
nitric.Run()
80+
}
81+
```
82+
83+
### See also
84+
85+
- [SqlDatabase.ConnectionString()](./sql-connection-string)

docs/reference/nodejs/sql/sql-connection-string.mdx

+2-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ const connStr = await db.connectionString()
3030

3131
### Connect with Prisma
3232

33-
```javascript file=<rootDir>/src/assets/snippets/sql-prisma-snippet.js
34-
35-
```
33+
<ImportCode file="/src/assets/snippets/sql-prisma-snippet.js" />
3634

3735
### Connect with Drizzle
3836

39-
```javascript file=<rootDir>/src/assets/snippets/sql-drizzle-snippet.js
40-
41-
```
37+
<ImportCode file="/src/assets/snippets/sql-drizzle-snippet.js" />

docs/reference/nodejs/sql/sql.mdx

+2-6
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,11 @@ const db = sql('my-data', {
5656

5757
### Connect with Prisma
5858

59-
```javascript file=<rootDir>/src/assets/snippets/sql-prisma-snippet.js
60-
61-
```
59+
<ImportCode file="/src/assets/snippets/sql-prisma-snippet.js" />
6260

6361
### Connect with Drizzle
6462

65-
```javascript file=<rootDir>/src/assets/snippets/sql-drizzle-snippet.js
66-
67-
```
63+
<ImportCode file="/src/assets/snippets/sql-drizzle-snippet.js" />
6864

6965
### See also
7066

src/config/reference/go.ts

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export const GoReference: NavGroup = {
3434
title: 'NewSecret()',
3535
href: '/reference/go/secrets/secret',
3636
},
37+
{
38+
title: 'NewSqlDatabase()',
39+
href: '/reference/go/sql/sql',
40+
},
3741
{
3842
title: 'NewBucket()',
3943
href: '/reference/go/storage/bucket',
@@ -215,6 +219,15 @@ export const GoReference: NavGroup = {
215219
},
216220
],
217221
},
222+
{
223+
title: 'SQL',
224+
items: [
225+
{
226+
title: 'SqlDatabase.ConnectionString()',
227+
href: '/reference/go/sql/sql-connection-string',
228+
},
229+
],
230+
},
218231
{
219232
title: 'Schedules',
220233
items: [

0 commit comments

Comments
 (0)