Skip to content

go-goe/sqlite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLite

This is a no CGO sqlite driver for GOE ORM based on https://pkg.go.dev/modernc.org/sqlite.

Features

  • 🪝 Connection Hook
  • 🧪 In Memory Database

Usage

Basic

package main

import (
	"github.com/go-goe/goe"
	"github.com/go-goe/sqlite"
)

type User struct {
	ID    int
	Name  string
	Email string `goe:"unique"`
}

type Database struct {
	User *User
	*goe.DB
}

func main() {
	db, err := goe.Open[Database](sqlite.Open("goe.db", sqlite.NewConfig(sqlite.Config{})))
}

Connection Hook

package main

import (
	"github.com/go-goe/goe"
	"github.com/go-goe/sqlite"
)

type User struct {
	ID    int
	Name  string
	Email string `goe:"unique"`
}

type Database struct {
	User *User
	*goe.DB
}

func main() {
	db, err := goe.Open[Database](sqlite.Open(filepath.Join(os.TempDir(), "goe.db"), sqlite.NewConfig(
		sqlite.Config{
			ConnectionHook: func(conn sqlite.ExecQuerierContext, dsn string) error {
				conn.ExecContext(context.Background(), "PRAGMA foreign_keys = OFF;", nil)
				return nil
			},
		},
	)))
}

In Memory Database

package main

import (
	"github.com/go-goe/goe"
	"github.com/go-goe/sqlite"
)

type User struct {
	ID    int
	Name  string
	Email string `goe:"unique"`
}

type Database struct {
	User *User
	*goe.DB
}

func main() {
	db, err := goe.Open[Database](sqlite.OpenInMemory(sqlite.NewConfig(sqlite.Config{})))
}

About

A SQLite Driver for GOE ORM

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages