Skip to content

Commit

Permalink
golang
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekwuno committed Feb 4, 2025
1 parent 3c45aa8 commit d00009a
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 45 deletions.
53 changes: 48 additions & 5 deletions src/screens/surrealist/docs/topics/authentication/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,54 @@ db.signin({
})
`,
go: `
db.Signin(map[string]string{
"user": "root",
"pass": "root",
})
`,
// Sign in as a root user
authData := &surrealdb.Auth{
Username: "root", // use your setup username
Password: "root", // use your setup password
}
token, err := db.SignIn(authData)
if err != nil {
panic(err)
}
// Sign in to authentication db using the namespace user
authData := &surrealdb.Auth{
Username: "root", // use your setup username
Password: "root", // use your setup password
Namespace = "test",
}
token, err := db.SignIn(authData)
if err != nil {
panic(err)
}
// Sign in to authentication db using the database user
authData := &surrealdb.Auth{
Username: "root", // use your setup username
Password: "root", // use your setup password
Namespace = "test",
Database = "test",
}
token, err := db.SignIn(authData)
if err != nil {
panic(err)
}
// Sign in to authentication db using the record accessmethod
authData := &surrealdb.Auth{
Username: "root", // use your setup username
Password: "root", // use your setup password
Namespace = "test",
Database = "test",
Access = "user",
Email = "[email protected]",
Password = "123456"
}
token, err := db.SignIn(authData)
if err != nil {
panic(err)
}
`,
csharp: `
// Sign in as root user
await db.SignIn(
Expand Down
20 changes: 13 additions & 7 deletions src/screens/surrealist/docs/topics/authentication/sign-up.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ export function DocsAuthSignUp({ language }: TopicProps) {
})
`,
go: `
db.Signup(map[string]string{
"NS": "clear-crocodile-production",
"DB": "web-scraping-application",
"SC": "user",
"email": "[email protected]",
"pass": "123456",
})
authData := &surrealdb.Auth{
Username: "root",
Password: "root",
Namespace = "test",
Database = "test",
Access = "user",
Email = "[email protected]",
Password = "123456"
}
token, err := db.SignUp(authData)
if err != nil {
panic(err)
}
`,
csharp: `
// With Record Access
Expand Down
12 changes: 8 additions & 4 deletions src/screens/surrealist/docs/topics/concepts/full-text-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ export function DocsConceptsFullTextSearch({ language }: TopicProps) {
DEFINE INDEX page_date_indexed ON page FIELDS date;');
`,
go: `
// Connect to a local endpoint
surrealdb.New("ws://localhost:8000/rpc");
// Connect to a remote endpoint
surrealdb.New("ws://cloud.surrealdb.com/rpc");
await db.RawQuery(
"
DEFINE TABLE page SCHEMALESS PERMISSIONS FOR select FULL;
DEFINE ANALYZER simple TOKENIZERS blank,class,camel,punct FILTERS snowball(english);
DEFINE INDEX page_hostname ON page FIELDS hostname;
DEFINE INDEX page_date_indexed ON page FIELDS date;
"
);
`,
csharp: `
await db.RawQuery(
Expand Down
2 changes: 1 addition & 1 deletion src/screens/surrealist/docs/topics/global/connecting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function DocsGlobalConnecting({ language }: TopicProps) {
// Connect to a local endpoint
surrealdb.New("ws://localhost:8000/rpc");
// Connect to a remote endpoint
surrealdb.New("ws://cloud.surrealdb.com/rpc");
surrealdb.New("wss://cloud.surrealdb.com/rpc");
`,
csharp: `
await db.Connect();
Expand Down
9 changes: 4 additions & 5 deletions src/screens/surrealist/docs/topics/schema/params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ export function DocsSchemaParams({ language }: TopicProps) {
await db.unset('name')
`,
go: `
// Assign a variable on the connection
db.Let("name", map[string]string{
"first": "ElecTwix",
"last": "Morgan Hitchcock",
// Assign the variable on the connection
db.Let("name", new Name {
FirstName = "Tobie",
LastName = "Morgan Hitchcock"
});
// Use the variable in a subsequent query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ db.delete('${table.schema.name}')
db.delete(RecordID('${table.schema.name}', 'h5wxrf2ewk8xjxosxtyc'))
`,
go: `
db.Delete("${table.schema.name}", map[string]interface{}{})
db.Delete[models.Table](db, models.Table("${table.schema.name}"));
`,
csharp: `
await db.Delete("${table.schema.name}");
Expand Down
16 changes: 13 additions & 3 deletions src/screens/surrealist/docs/topics/tables/inserting-records.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { useDocsTable } from "../../hooks/table";
export function DocsTablesInsertingRecords({ language }: TopicProps) {
const table = useDocsTable();

const fieldName =
table.fields.find(({ name }: { name: string }) => !["id", "in", "out"].includes(name))
?.name ?? "id";

const snippets = useMemo<Snippets>(
() => ({
cli: `
Expand Down Expand Up @@ -53,9 +57,15 @@ db.insert('${table.schema.name}', [
])
`,
go: `
db.Query("INSERT INTO ${table.schema.name} {
field: value
};")
// Insert an entry
person2, err := surrealdb.Insert[${fieldName}](db, models.Table("${table.schema.name}"), map[interface{}]interface{}{
"Name": "Jane",
"Surname": "Smith",
"Location": models.NewGeometryPoint(-0.12, 22.01),
})
if err != nil {
panic(err)
}
`,
csharp: `
await db.Merge("${table.schema.name}", data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { useDocsTable } from "../../hooks/table";

export function DocsTablesSelectAllFields({ language }: TopicProps) {
const table = useDocsTable();
const fieldName =
table.fields.find(({ name }: { name: string }) => !["id", "in", "out"].includes(name))
?.name ?? "id";

const snippets = useMemo<Snippets>(
() => ({
Expand All @@ -23,7 +26,7 @@ export function DocsTablesSelectAllFields({ language }: TopicProps) {
db.select('${table.schema.name}');
`,
go: `
db.Select('${table.schema.name}');
db.Select[[]${(table.schema.name)}, models.Table](db, models.Table("${fieldName}"))
`,
csharp: `
await db.Select<${pascal(table.schema.name)}>("${table.schema.name}");
Expand Down
2 changes: 1 addition & 1 deletion src/screens/surrealist/docs/topics/tables/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function DocsTablesSelect({ language }: TopicProps) {
db.select('${fieldName}')
`,
go: `
db.Select[[]${(table.schema.name)}, models.Table](db, models.Table("${fieldName}"))
`,
csharp: `
await db.Select<Person>(new StringRecordId("person:h5wxrf2ewk8xjxosxtyc"));
Expand Down
33 changes: 16 additions & 17 deletions src/screens/surrealist/docs/topics/tables/updating-records.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,26 @@ export function DocsTablesUpdatingRecords({ language }: TopicProps) {
db.update("${table.schema.name}").await?;
`,
py: `
# Update all records in a table
db.update('${table.schema.name}', {name: "Jaime"})
# Update all records in a table
db.update('${table.schema.name}', {name: "Jaime"})
# Update a record with a specific ID
db.update(RecordID('${table.schema.name}', 'tobie'), {
"name": 'Tobie',
"settings": {
"active": True,
"marketing": True,
}
})
# Update a record with a specific ID
db.update(RecordID('${table.schema.name}', 'tobie'), {
"name": 'Tobie',
"settings": {
"active": True,
"marketing": True,
}
})
`,
go: `
db.Update("${table.schema.name}", map[string]interface{}{
"name": "ElecTwix",
"settings": map[string]bool{
"active": true,
"marketing": true,
},
});
// Update a single record in the "persons" table
updatedPerson, err := surrealdb.Update[${table.schema.name}](db, models.RecordID("persons", "person123"), Person{
Name: "John",
Surname: "Smith", // Updated surname
Location: models.NewGeometryPoint(-0.12, 23.00), // Updated location
})
`,
csharp: `
await db.Upsert("${table.schema.name}", data);
Expand Down

0 comments on commit d00009a

Please sign in to comment.