• Stars
    star
    479
  • Rank 91,752 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

golang database modelling library

Modl: Go database model & mapping

Build Status Godoc

Modl is a library which provides database modelling and mapping. It is a fork of James Cooper's wonderful gorp.

Note. Modl's public facing interface is considered unfinished and open to change. The current API will not be broken lightly, but additions are likely. As Gorp's behavior moves on, Modl may adopt some of it or may not.

Goals

Modl's goal is to clean up bits of gorp's API, add some additional features like query building helpers and additional control over SQL generation, and to reuse lower level abstractions provided in sqlx. The driving philosophies behind modl are:

  • If something can be done in database/sql, do it that way
  • Go is not a good declarative language, do not abuse struct tags
  • Expose as much as possible to facilitate extension by other libraries
  • Avoid abstractions which provide initial convenience but must eventually be abandoned
  • Avoid reflect and cache its results where possible, use where necessary

Features

  • Bind struct models to tables
  • CRUD helpers for bound structs
  • Create schema from database model (great for testing)
  • Pre/post insert/update/delete hooks
  • Automatic binding of auto increment PKs after insert
  • Delete & Fetch by primary keys (w/ multi-key support)
  • Sql trace logging
  • Bind arbitrary SQL queries to a struct
  • Optional optimistic locking using a version column (for update/deletes)

Differences from Gorp

Since modl is a gorp fork, here are some of its major behavioral differences:

  • Field names are mapped to all-lowercase sql equivalents. Capitalization is an artifact of visibility, and this was required for compatibility with sqlx.
  • No more struct/slice returns, pass pointers to methods instead
  • Many panics in gorp are errors in modl
  • TypeConverters are removed in favor of implementing sql.Scanner & driver.Valuer for custom types.

Testing

To use the test-all script, set the following environment variables:

# mysql DSN, note parseTime arg for time scanning support:
MODL_MYSQL_DSN="username:password@/dbname?parseTime=true"

# postgres DSN, like:
MODL_POSTGRES_DSN="user=username password=pw dbname=dbname sslmode=disable"

# sqlite DSN, which is a path
MODL_SQLITE_DSN="/dev/shm/modltest.db"

# optional, will fail the test if any DBs are skipped (for CI, mostly)
MODL_FAIL_ON_SKIP=true

In addition to this, you can create an environ file in this directory which will be sourced and ignored by git. You can continue to use the MODL_TEST_DSN and MODL_TEST_DIALECT variables if you want to manually run go test or if you want to run the benchmarks, as described below.

The original README.md follows:

API Stability

The API of Modl has been quite stable since its conception. Changes to the API are avoided as much as possible but there is currently no promise of forward or backward compatibility.

Supported Databases

Modl relies heavily upon the database/sql package, and has a Dialect interface which can be used to smooth over differences between databases. There is a list of sql drivers on the Go wiki, most of which Modl should be compatible with. Dialects are provided for:

  • MySQL
  • PostgreSQL
  • sqlite3

The test suite is continuously run against all of these databases.

Documentation

API Documentation is available on godoc.

Performance

Modl performs similar to Gorp. There are benchmarks in modl_test.go which will benchmark native querying w/ database/sql and manual Scanning with what modl does. Modl should perform between 2-3% slower than hand-done SQL.

Contributors

The original contributors to gorp are:

  • @coopernurse - James Cooper
  • @robfig - Rob Figueiredo
  • @sqs - Quinn Slack
  • matthias-margush - column aliasing via tags

More Repositories

1

sqlx

general purpose extensions to golang's database/sql
Go
16,176
star
2

humanize

python humanize functions
Python
1,677
star
3

jsonq

simple json field access for golang
Go
586
star
4

johnny-cache

johnny cache django caching framework
Python
305
star
5

monet

golang blog
Go
196
star
6

speedparser

feedparser but faster and worse
Python
101
star
7

gowiki

single-file single-executable wiki written in golang
Go
77
star
8

jigo

an attempt at a jinja2 implementation in go
Go
71
star
9

dmc

dmc runs commands via ssh on multiple machines
Go
34
star
10

django-slow-log

django slow request log
Python
32
star
11

micromongo

tiny fast python orm-ish tools for mongodb
Python
27
star
12

mandira

language agnostic logic-light template system
Go
27
star
13

arachne

a complex but scalable web spider
Python
25
star
14

aranha

simple python gevent web spider
Python
23
star
15

python-github

simple python github api2 library
Python
16
star
16

cm

very simple config manager
Go
15
star
17

par2ools

par2 tools (par2ls, par2mv, par2unrar)
Python
12
star
18

contact-form

server that implements an email contact form for an otherwise static website
Go
11
star
19

what-the-sql

online sql test
Go
11
star
20

euler.go

project euler solutions in go
Go
9
star
21

jmoiron.net

personal blog + website written with flask
Python
8
star
22

dotfiles

dotfiles + cm
Vim Script
8
star
23

jinkies

jinkies is a simple jenkins cli
Python
6
star
24

ongaku

http music player for local files streamable to a chromecast via chrome tab streaming
Go
6
star
25

gaspar

generic eventlet+zmq worker library
Python
5
star
26

kokuen

django-app performance tracking w/ statsd + graphite
Python
5
star
27

pdf2zip

converts image-based pdfs to a zipfile full of extracted images
Python
5
star
28

gevent-memcache-bench

python memcached speed tests w/ and w/o gevent
Python
4
star
29

etod

epoch to date
Go
3
star
30

redtape

simple program to create simple html docs from simple markdown files
Python
3
star
31

uromkan

python unicode romaji to kana conversion
Python
3
star
32

iris

python command-line photo management thing
Python
2
star
33

daneel

Python
2
star
34

chapman

chapman python backup nonsense
Python
2
star
35

nvidia-gpu-temp

Python
1
star
36

terminal-schemer

portable style scheme application for mate-terminal and gnome-terminal
Go
1
star
37

cs101

simplistic explorations of basic CS data structures & algorithms
Go
1
star
38

pctilde

pctilde emulates the behavior of the zsh PS1 var '%~'
Go
1
star
39

golang-sdk

Go
1
star
40

ulv-covers-modern

ulv covers for gregtech ceu modern
Java
1
star