Table of Contents

Introduction Installation Projects Tables Inserts Searches Updates Deletes CLI Production Installation Partial Autoscaling Good Practices Conclusion

Inserts - Flaarum Tutorials (Golang)    Python

Insertion Method 1

The first method of insertion expects a map[string]any for its data. Flaarum provides no statements for inserts. One would need to use a function call for insertions.

Sample Code

package main

import (
	"fmt"
	"github.com/saenuma/flaarum"
)

func main() {
	cl := flaarum.NewClient("127.0.0.1", "not-yet-ready", "first_proj")
	toInsert := map[string]any {
		"userid": 32,
		"roleid": 12,
	}
	retid, err := cl.InsertRowAny("user_roles", toInsert)
	if err != nil {
		flErr := err.(flaarum.FlaarumError)
		if flErr.Code == 21 {
			fmt.Println("An element is not unique")
		}
	}
	fmt.Println(retid)
}

The flaarum lib expects the address of the database, its keystring (like a password) and the name of the project.

All Error Codes

Insertion Method 2

The second method of insertion expects a map[string]string for its data. This introduces some comfort in some situations.

Sample Code

package main

import (
	"github.com/saenuma/flaarum"
)

func main() {
	cl := flaarum.NewClient("127.0.0.1", "not-yet-ready", "first_proj")
	toInsert := map[string]string {
		"userid": "32",
		"roleid": "12",
	}
	retid, err := cl.InsertRowStr("user_roles", toInsert)
	if err != nil {
		panic(err)
	}
	
}

< Previous Next >