Code Monkey home page Code Monkey logo

reform's People

Contributors

ababo avatar alekseymartynov avatar aleksi avatar artemgavrilov avatar dependabot[bot] avatar eaglemoor avatar fpawel avatar haraldnordgren avatar hectorj avatar joaodrp avatar lukateras avatar plod avatar quasilyte avatar sgmv avatar xaionaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reform's Issues

Support of composite primary keys

When I'm trying to define a composite Primary Key

//reform:raw_records
type RawRecord struct {
        ModelBase

        Date           time.Time `reform:"date,pk"`
        SensorId       int       `reform:"sensor_id,pk"`
        ChannelId      int       `reform:"channel_id,pk"`
        Value          int       `reform:"value"`
        ConvertedValue int       `reform:"converted_value"`
}

it returns an error:

reform: . RawRecord.go: reform: RawRecord has field SensorId with with duplicate "pk" label in "reform:" tag (first used by Date), it is not allowed

Seems the feature is not implemented, yet. But if I don't set any PK then reform thinks it's just a view (not a table). So I have to make an extra auto-increment field to use this model by reform.

This issue is just about "please implement support of composite Primary Keys" :)

panic: template: struct:27: illegal number syntax: "-"

Please help me to understand the reason of the next error:

$ go version
go version go1.5.1 linux/amd64
$ reform
panic: template: struct:27: illegal number syntax: "-"

goroutine 1 [running]:
text/template.Must(0x0, 0x7fafb582f028, 0xc82000aaf0, 0x0)
        /usr/lib/go/src/text/template/helper.go:23 +0x4b
main.init()
        /home/xaionaro/gocode/src/gopkg.in/reform.v1/reform/template.go:149 +0x212

$ cd /home/xaionaro/gocode/src/gopkg.in/reform.v1/reform; git log | head -1
commit d60dbfa976a39e47697f4038a37c7ae749030621

Add tag support for sql

Usually, it's very useful to mark queries with some tags.

This code db.Tag("disable_user:%s", userId).Update(user) might produce the next query UPDATE /* disable_user:10 */ ...

Support for MS SQL

3 steps:

  1. Add dialect for MS SQL. That should be easy.
  2. Fix reform and/or tests. Should be easy too, and likely not even required.
  3. The hardest step: add Travis CI integration. MS SQL should be provisioned only on builder with specified target.

The first one who will send a working pull request will receive a squishable gopher from me and @GolangShow!

Local testing

Try test local:

$ make test_mattn_go-sqlite3
rm -f reform-test.sqlite3
sqlite3 -bail reform-test.sqlite3 < internal/test/sql/sqlite3_init.sql
sqlite3 -bail reform-test.sqlite3 < internal/test/sql/data.sql
sqlite3 -bail reform-test.sqlite3 < internal/test/sql/sqlite3_set.sql
go test -coverprofile=test_mattn_go-sqlite3.cover
# reform
package reform_test
    imports github.com/AlekSi/reform/internal/test/models: use of internal package not allowed
FAIL    reform [setup failed]
make: *** [test_mattn_go-sqlite3] Error 1

Nested transactions via savepoints

Add method to TX to execute SAVEPOINT:

func (tx *TX) Begin() *TX { }

Commit() and Rollback() of nested "transaction" should execute RELEASE SAVEPOINT and ROLLBACK TO SAVEPOINT.

Relevant discussion: golang/go#7898.

Schema support

Table & View need support schema prefix if need use it.
Example, we have same table in public schema & same table in chunks schema.
If we try change Name like this

func (v *personeView) Name() string {
    return "public.persone"
}

we have sql like a SELECT public.persone.id, public.persone.name, ...

Limit for *One* functions?

tail needed for WHERE or LIMIT part of query. But function, whitch return just one struct need auto add limit 1 automatically.

Use go/format when -gofmt=false

Invoking an external gofmt command is relatively slow on Windows. Let's use go/format and do formatting ourselves when -gofmt=false. We should continue using gofmt -s by default because -s simplifies our generated code, and it is not possible yet to do it with go/format.

Automatically expand placeholders for IN and lists

reform has different methods to make IN statements now

  1. FindAllFrom(view View, column string, args ...interface{})
  2. SelectRows(view View, tail string, args ...interface{})

The first one handles just one IN for a column, In the second I have to make placeholders for IN by myself.

What I want is the same logic as in the first case, but reform should automatically expand args element to $1, $2 if this element has a slice value.

UPSERT with single database statement

Several RDBMS support UPSERT (INSERT or UPDATE with a single statement):

We should add Upsert method to reform. It should use a single RDBMS-specific statement. Behaviour could be RDBMS-specific too but well documented (see PostgreSQL wiki link for the good overview). It should not try to emulate it in unsupported RDBMS with several queries and/or transactions, it will return an error instead.

WIP branch that could be useful: https://github.com/go-reform/reform/tree/upsert.

Linter

Semi-crazy idea: linter to catch incorrect error handling. For example, some methods are documented to never return ErrNoRows. Linter can check user's code and find cases where result is compared with ErrNoRows.

JOINs

Hell froze over! 😄

Let's add just enough for one-to-one and one-to-many relationships.

type Foo struct {
  ID int `reform:"id,pk"`
}

type Bar struct {
  ID int `reform:"id,pk"`
}

type Baz struct {
  FooID int   `reform:"foo_id"`
  BarID int   `reform:"bar_id"`
  Foo   *Foo  `reform:"FIXME_WHAT_THERE"`
  Bars  []Bar `reform:"FIXME_WHAT_THERE"`
}

LEFT OUTER JOINs only.

Better Travis CI configuration

Currently, we run tests with 1.6 and tip for PostgreSQL 9.1 and SQLite.
We need to:

  • add MySQL;
  • add PostgreSQL 9.2-9.6;
  • add different versions of MySQL.

Alternatively, we can switch to https://circleci.comI was told it's better for such tests I don't think so anymore.

Support anonymous struct fields

I would like to make use of Postgresql inheritance. To do that it's logical to use anonymous struct fields:

//reform:parents
type Parent struct {
    ID   int    `reform:"id,pk"`
    Name string `reform:"name"`
}

//reform:children
type Child struct {
    Parent
    Desc string `reform:"desc"`
} 

but that is not supported.

Help error

Help error

*main.Users

&main.Users{ID:1, Username:"zer", Password:"zer", Status:"active", Channel:"1", Created_at:1466744563, Last_activity_at:1466744563}panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x38 pc=0x8bffa]

goroutine 1 [running]:
panic(0x3681c0, 0xc82000a0c0)
        /usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:481 +0x3e6
github.com/go-reform/reform.(*Querier).Insert(0xc820015260, 0x6c28b0, 0xc82005e6c0, 0x0, 0x0)
        /Users/zer/golang/src/github.com/go-reform/reform/querier_commands.go:35 +0x70a
main.Conn()
        /Users/zer/dev/go/userapi/database.go:53 +0x7e6
main.main()
        /Users/zer/dev/go/userapi/main.go:22 +0x14
exit status 2

Support for nested structs?

It will be nice if reform could map nested structs to a single table.
Example:

type DateTime struct {
    Date time.Time `reform: date`
    Timezone string `reform: timezone`
}

// reform:events
type Event struct {
    Start DateTime `reform: start_`
    End DateTime `reform: end_`
}

And that would map to a table with start_date, start_timezone, end_date and end_timezone columns.

Generate code for slices

At the moment, giving type Foo, we generate FooTable (or FooView). We can also generate FooSlice for a slice of Foo with some helpers:

type FooSlice []Foo

func (f FooSlice) Structs() []Struct { }
func MakeFooSlice(structs []Struct) FooSlice { }

This will give us helpful reflection-free methods:

  • SelectAllTo
  • something else?

Multi insert

I think it's a good idea for orm have a method for Insert array struct?

example

DB.Insert(s []Struct)

// SQL
INSERT INTO `table name` (`col1`, `col2`, `col3`) VALUES (s1.col1, s1.col2, s1.col3), (...)

If need, i can write It

We need Examples

Нужно как можно больше примеров. Хотя бы с инициализацией DB.

Столкнулся с проблемой при создании reform.NewDB, а именно с Logger.
Стандартный Logger я использовать не могу, Logger который interface тоже, а PrintfLogger, который сам напрашивается для использования, тоже не могу применить, тк не знаю кто поддерживает type Printf func(format string, a ...interface{})

Если бы пример на главной странице был более подробный, с открытием database/sql соединения, созданием логера и использовании — это очень сильно помогло бы разобраться что да как.

Update with tail

Some models can be updated with additional conditions, ie when I about to update OrderTable, I need to ensure the owner with user_id. For now I must do query first to ensure the owner.

Drone CI configuration

Update: see #135.


War. War with Travis CI (#5) never changes. While it's free and fast, it has a major downside: it's way too hard to add a non-trivial build configuration and debug it, and we want to test all the non-trivial configurations.

Let's move to self-hosted Drone CI 0.5. Two biggest benefits:

  • It will make local testing (and CI setup debugging!) much easier: just drone exec.
  • It will allow running tests with different versions of databases and Go much easier.

Downsides:

  • I pay for hosting.
  • A build is slow on a cheap virtual machine, and a fast VM is expensive.

My hosted instance is was here. Currently, it runs 60 configurations.

Maybe there will be free Drone service of OSS projects. Or maybe I should investigate how to spin up fast VM for build agent, make a build and shut it down.

AppVeyor will stay for native Windows builds. Travis CI will stay for current basic configurations because it's fast – at least until it starts to drag us down.

Steps:

  • Full CI configuration.
  • Local configuration for drone exec.
  • Add codecov.io integration.
  • Remove coveralls integration.
  • Use gocoverutil.

"reform-db init" command

reform-db init models should connect to a database, inspect information_schema or equivalent, and generate model files from it.

See also #75 and #102.

See PR #113.

Add support Cassandra

3 steps:

  1. Add dialect for Cassandra. That should be easy.
  2. Fix reform and/or tests. Should be easy too, and likely not even required.
  3. The hardest step: add Travis CI integration. Cassandra should be provisioned only on builder with specified target.

The first one who will send a working pull request will receive a squishable gopher from me and @GolangShow!

Logo

We need a unique logo. With a gopher. Some possible symbols:

  • something database-related: UML database symbols, etc.
  • something about reform: gopher on tribune?

@bosenok wanted to help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.