Extypes - Extra data types useful for database

ExTypes

Extra data types useful for database

JSON Object

JSON Object is useful for accepting any type for postgres JSONB, Array, and more. You can't put or retrieve them directly.

Example

package sample

import (
	"context"
	"database/sql"
	"fmt"

	"github.com/nasermirzaei89/extypes"
)

type Foo struct {
	ID       string
	Tags     []string
	Metadata map[string]interface{}
}

func InsertFoo(ctx context.Context, db *sql.DB, foo Foo) error {
	tags := extypes.NewJSONObject(foo.Tags)
	metadata := extypes.NewJSONObject(foo.Metadata)

	_, err := db.ExecContext(ctx, "INSERT INTO foo (id, tags, metadata) VALUES ($1, $2, $3)", foo.ID, tags, metadata)
	if err != nil {
		return fmt.Errorf("error on exec insert query")
	}

	return nil
}

func FindFoo(ctx context.Context, db *sql.DB, fooID string) (*Foo, error) {
	var (
		res      Foo
		tags     extypes.JSONObject
		metadata extypes.JSONObject
	)

	err := db.QueryRowContext(ctx, "SELECT id, tags, metadata FROM foo WHERE id = $1", fooID).Scan(&res.ID, &tags, &metadata)
	if err != nil {
		return nil, fmt.Errorf("error on query row")
	}

	res.Tags = tags.GetStringSlice()
	res.Metadata = tags.GetStringInterfaceMap()

	return &res, nil
}
Owner
Naser Mirzaei
Yet Another Developer
Naser Mirzaei
Similar Resources

Kalasa is a NoSQL database and provides more data structures for ease of use.

Kalasa is a NoSQL database and provides more data structures for ease of use.

Kalasa Kalasa is a NoSQL database and provides more data structures for ease of use. 简体中文 | English 特 性 嵌入的存储引擎 数据可以加密存储 可以自定义实现存储加密器 即使数据文件被拷贝,也保证存储数

Dec 31, 2022

HBase Exporter,fetch data from jmx for region-level data.

HBase Exporter Prometheus exporter for HBase which fetch data from hbase jmx, written in Go. You can even see region-level metrics. Installation and U

Nov 4, 2022

Kstone is an etcd management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd data, and intelligent diagnosis.

Kstone is an etcd management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd data, and intelligent diagnosis.

Kstone 中文 Kstone is an etcd management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd

Dec 27, 2022

Conduit - Data Integration for Production Data Stores

Conduit - Data Integration for Production Data Stores

Conduit Data Integration for Production Data Stores. 💫 Overview Conduit is a da

Jan 3, 2023

💧 Visual Data Preparation (VDP) is an open-source tool to seamlessly integrate Vision AI with the modern data stack

💧 Visual Data Preparation (VDP) is an open-source tool to seamlessly integrate Vision AI with the modern data stack

Website | Community | Blog Get Early Access Visual Data Preparation (VDP) is an open-source tool to streamline the end-to-end visual data processing p

Jan 5, 2023

Vilicus is an open source tool that orchestrates security scans of container images(docker/oci) and centralizes all results into a database for further analysis and metrics.

Vilicus is an open source tool that orchestrates security scans of container images(docker/oci) and centralizes all results into a database for further analysis and metrics.

Vilicus Table of Contents Overview How does it work? Architecture Development Run deployment manually Usage Example of analysis Overview Vilicus is an

Dec 6, 2022

StaticBackend is a simple backend server API handling user mgmt, database, storage and real-time component

StaticBackend is a simple backend server API handling user mgmt, database, storage and real-time component

StaticBackend is a simple backend that handles user management, database, file storage, forms, and real-time experiences via channel/topic-based communication for web and mobile applications.

Jan 7, 2023

The Oracle Database Operator for Kubernetes (a.k.a. OraOperator) helps developers, DBAs, DevOps and GitOps teams reduce the time and complexity of deploying and managing Oracle Databases

The Oracle Database Operator for Kubernetes (a.k.a. OraOperator) helps developers, DBAs, DevOps and GitOps teams reduce the time and complexity of deploying and managing Oracle Databases. It eliminates the dependency on a human operator or administrator for the majority of database operations.

Dec 14, 2022

A tiny self-contained pasting service with a built-in database.

A tiny self-contained pasting service with a built-in database.

Dec 18, 2021
Related tags
Optional is a library that provides option types for Go types.

Option Optional is a library that provides option types for Go types. Installation Golang version 1.18 + required go get -u github.com/eatmoreapple/op

Nov 9, 2022
Set of Kubernetes solutions for reusing idle resources of nodes by running extra batch jobs

Caelus Caelus is a set of Kubernetes solutions for reusing idle resources of nodes by running extra batch jobs, these resources come from the underuti

Nov 22, 2022
A block parser tool that allows extraction of various data types on DAS

das-database A block parser tool that allows extraction of various data types on DAS (register, edit, sell, transfer, ...) from CKB Prerequisites Ubun

Nov 11, 2022
Cli tool to save useful links to read it later
Cli tool to save useful links to read it later

lnk - Cli tool to save useful links still in development Usage lnk <new|list> [url] - new: creates a new link url: required params, which i

Jun 23, 2022
go-ima is a tool that checks if a file has been tampered with. It is useful in ensuring integrity in CI systems
go-ima is a tool that checks if a file has been tampered with.  It is useful in ensuring integrity in CI systems

go-ima Tool that checks the ima-log to see if a file has been tampered with. How to use Set the IMA policy to tcb by configuring GRUB GRUB_CMDLINE_LIN

Apr 26, 2022
Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism
Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism

nhi is a revolutionary tool which automatically captures all potentially useful information about each executed command and everything around, and delivers powerful querying mechanism.

Nov 29, 2022
Package trn introduces a Range type with useful methods to perform complex operations over time ranges

Time Ranges Package trn introduces a Range type with useful methods to perform c

Aug 18, 2022
simple web app that print its environment variable, useful for testing on k8s

Index Sample web app that pints environment variables. Start it: docker-compose up Use it: > curl localhost:8080 PATH=/usr/local/sbin:/usr/local/bin:/

Jan 10, 2022
Some useful tools to help manage attachments in my local markdown projects.

Some useful tools to help manage attachments in my local markdown projects.

Oct 8, 2022
A seed repository that contains a Go project that accepts input via a REST API and saves data to an Oracle database.

rest-oracle-go-seed A seed repository that contains a Go project that accepts input via a REST API and saves data to an Oracle database. Why Oracle? T

Apr 18, 2022