peridot/vendor/go.ciq.dev/pika
2023-08-25 18:39:59 +02:00
..
parser Use BUILD files instead of BUILD.bazel 2023-08-22 17:20:03 +02:00
.gitignore Initial commit 2023-08-21 18:01:10 +02:00
.golangci.yml Initial commit 2023-08-21 18:01:10 +02:00
BUILD Use BUILD files instead of BUILD.bazel 2023-08-22 17:20:03 +02:00
CONTRIBUTORS Initial commit 2023-08-21 18:01:10 +02:00
COPYRIGHT Initial commit 2023-08-21 18:01:10 +02:00
LICENSE Initial commit 2023-08-21 18:01:10 +02:00
pika_aip_filter_proto.go Initial commit 2023-08-21 18:01:10 +02:00
pika_aip_filter.go Initial commit 2023-08-21 18:01:10 +02:00
pika_page_token.go govendor 2023-08-25 18:39:59 +02:00
pika_page_token.go.orig govendor 2023-08-25 18:39:59 +02:00
pika_psql.go Initial commit 2023-08-21 18:01:10 +02:00
pika.go Initial commit 2023-08-21 18:01:10 +02:00
README.md Initial commit 2023-08-21 18:01:10 +02:00
utils.go Initial commit 2023-08-21 18:01:10 +02:00

pika

ORM-like SQL builder

Features

  • Any feature supported by sqlx
  • Support for AIP-160 filtering
  • Utilities to help with AIP-132 for List calls
  • Support for determining filters based on Protobuf messages
  • Automatically selecting columns in struct
  • Count, Get, All, Create, Update, Delete and more.
  • Support for simple joins

Example

Simple connect and Get

package main

import (
	"go.ciq.dev/pika"
	"log"
)

type User struct {
	PikaTableName string `pika:"users"`
	ID            int64  `db:"id" pika:"omitempty"`
	Name          string `db:"name"`
}

func main() {
	psql, _ := pika.NewPostgreSQL("postgres://postgres:postgres@localhost:5432/test")
	args := pika.NewArgs()
	args.Set("id", 1)
	qs := pika.Q[User](psql).Filter("id=:id").Args(args)
	user, _ := qs.Get()
	
	log.Println(user)
}

AIP-160

package main

import (
	"go.ciq.dev/pika"
	"log"
)

type Article struct {
	PikaTableName string    `pika:"users"`
	ID            int64     `db:"id" pika:"omitempty"`
	CreatedAt     time.Time `db:"created_at" pika:"omitempty"`
	Title         string    `db:"title"`
	Body          string    `db:"body"`
}

func main() {
	psql, _ := pika.NewPostgreSQL("postgres://postgres:postgres@localhost:5432/test")

	qs := pika.Q[Article](s.db)
	// Get the following articles
	//   * The title MUST contain Hello and the body MUST contain World
	//   * If the above is not match, the article MUST be created before 2023-07-30
	qs, err := qs.AIP160(`(title:"Hello" AND body:"World") OR (created_at < 2023-07-30T00:00:00Z)`, pika.AIPFilterOptions{})
	if err != nil {
		return nil, err
	}

	rows, err := qs.All()
	if err != nil {
		return nil, err
	}

	log.Println(rows)
}