eaigner / hood Goto Github PK
View Code? Open in Web Editor NEWDatabase agnostic ORM for Go
License: MIT License
Database agnostic ORM for Go
License: MIT License
If the schema contains a time.Time
field, the migration tool should automatically add a "time"
import at the top.
A la rake db:migrate
Support sqlite dialect. Maybe using: http://code.google.com/p/gosqlite/ or https://github.com/kuroneko/gosqlite3
how to implement where in ?
How about we define a interface for a table then define the table property in method?
like
type Table interface{
Properties() map[string]interface{}
}
Sometimes there are unwanted files in db/migrations, e.g. editor backup files. It causes strange errors.
Implementing the migration system changed the dialect interface radically. Most methods have been ported from the postgres dialect, but sqlite3 only supports a subset of ALTER TABLE
, so some methods were left out for time reasons.
Complete RenameColumn
, ChangeColumn
and DropColumn
implementations.
Hi,
I'm playing around with hood and I noticed that the readme is either wrong to specify that hood.New returns a tuple or that hood.New should return a tuple after all.
Cheers, Stefan
The current hood tool is too tightly tied to the config.json, make it more configurable and flexible via command line flags.
Trying to select from a table with a null value will cause a crash. Do something like this in SQL:
create table test (a integer not null, b varchar);
insert into test values (1, null);
Then with Hood, if you do this, you'll get a panic:
type Test struct {
Id hood.Id
Test string
}
vals := []Test{}
hd.FindSQL(&vals, "select * from test")
That crashes consistently.
Hello Erik,
First of all, thank you very much for this awesome package!
I'm developing a web application and I'm strongly considering using hood. However I will be using Sqlite3, which isn't currently supported. But I notice that there is a branch "sqlite3", so I'm just wondering if you have been working on sqlite3 support, and if so, would you consider it stable enough to be used in production? Can I just put splite3.go into the master branch and expect everything to work?
Specifically, I will just need to be able to create/drop tables, create/delete/query items, and ideally declare has-many and one-to-one relationships. Are these functionalities currently there?
Thank you for your time.
Best,
Derek
Migrations should autogenerate a schema.go
file
The postgres driver stores dates without timezone
the "OrderBy" method needs an descending option.
or add another method like "OrderByDesc"
Implement a DeleteFrom
method, to allow statements like
DELETE FROM table WHERE condition
Proposed syntax:
hd.Where("a", "=", "b").DeleteFrom("table")
$ /bin/hood create:config
panic: open /Users/justin/repos/goHood/db/config.json: no such file or directory
goroutine 1 [running]:
main.init·1()
/usr/local/go/src/pkg/github.com/eaigner/hood/cmd/cmd.go:56 +0x54c
main.init()
/usr/local/go/src/pkg/github.com/eaigner/hood/cmd/templates.go:5 +0xf9
goroutine 2 [syscall]:
created by runtime.main
/usr/local/go/src/pkg/runtime/proc.c:221
No tests for find, and the original Find with mymysql drv returns <[]uint8,Value> for string fields.
Rollback doesn't seem to behave correctly sometimes, investigate!
I was hoping to use the following code:
hood.Where("lower(username)", "=", "eaigner").Limit(1).Find(&user)
But it looks like hood is quoting the first argument resulting in a bad query (MySQL).
Cache models based on table name
Generating the ModelIndex instances is not necessary every time.
I know aggregate functions are not implemented yet as methods.
But there should be a way to use them through Select
or FindSql
right? I tried several variations but getting pq: column "max(date)" does not exist
.
Can anyone help me with this please?
I want to use this with a database that has a TitleCase naming convention -- is there any way to do it? I didn't see any way to override the snake cased naming convention.
Thanks!
You show in your "Basic Example":
func main() {
// Open a DB connection, use New() alternatively for unregistered dialects
hd, err := hood.Open("postgres", "user=hood dbname=hood_test sslmode=disable")
if err != nil {
panic(err)
}
// Create a table
type Fruit struct {
Id hood.Id
Name string `validate:"presence"`
Color string
}
err = hd.CreateTable(&Fruit{})
However when I try to replicate this flow myself I receive an error saying
panic: CreateTable can only be invoked inside a transaction
Otherwise a go get ./...
on the db dir will fail
Use the least amount of memory overhead
Implement RenameColumn
, ChangeColumn
and DropColumn
for sqlite3
How do you feel about adding a hook that runs after loading an entity? I use this feature (in Gorp) presently for two things:
Although, it looks like there is no way to issue queries from the hook, so use case (1) would not apply anyway.
The ` character cannot be used in templates at the moment.
[]byte
fields created in a migration show up as []uint8
in the generated schema.go
I'm just curious if you were planning to handle loading of relations at any point?
e.g. If a User has an associated Account, would you say it should be represented as:
type User struct {
AccountId hood.Id
}
and it's up to the user to select it separately when they want?
Add tag sql:"index(foo)"
resulting in SQL CREATE INDEX foo ON table_name (column_name)
Hello,
When deploying on heroku, one can expect to use the DATABASE_URL
environment variable to specify the database.
That variable is easily parsable to be opened even by hood.
import (
"github.com/lib/pq"
"github.com/eaigner/hood"
)
url := mustGetenv("DATABASE_URL")
parsed, _ := pq.ParseURL(url)
h, _ := hood.Open("postgres", parsed)
It would be very nice if when there is no db/config.json
, hood could fallback on using this environment variable.
I might find some time to work on this in the few weeks. This issue is meant to open potential discussions about it.
Add a validation syntax e.g. validates:"minlen(4),maxlen(12)"
I have move the CreateTable calling behind the tx := hd.Begin()
,I still get an error
panic: CreateTable can only be invoked inside a transaction
Hey,
I haven't glanced at the code yet, but based on the examples I'd like to highlight the established convention for struct tags. hood shouldn't claim the entire struct tag, and should coexist peacefully with other things that might be interested (such as encoding/json
).
There's an API in reflect, StructTag.Get
, which will parse the standard format and give you only the requested section back. So, in all the places that you extract the entire StructTag from the struct using reflect
, you can instead use StructTag.Get
to parse out a "hood" section with the same behavior, which would allow coexistence like so:
type User struct {
Name string `json:"user_name,omitempty" hood:"pk"`
}
Very ideal for declaring options for both encoding/json
and hood, which I would foresee as a common occurrence.
When a transaction is started and a new object is saved, Commit()
won't complain with an error if an unique index is violated (using Postgres).
All parameters should be quoted. We most likely have to break some API for that (e.g. Where).
The current migration implementation seems not easy to use.
I want migration to be executed in the application.
We can provide some APIs to execute a sequence of migration and associate each migration command with a version number.
the schema after each version of migration can be stored in local file, and will be used to check if new migration is added.
And I also want database level migration, like create database, rename database.
All the results with underscore names become camelcased and are not added to the returned struct if it has underscored names.
When creating the table, no warning is given about this and the table columns are not converted to camelcase either.
No mention about this in the documentation.
Couldn't find mention of what license this is released under, please include a LICENSE file.
Thanks!
Current Find method requires a slice of structs, this will consumes more memory as struct value will be unnecessarily copied twice when append to and get from the slice.
I'm going to implement it on my branch, and force slice element to be pointer. this will break working code though
The TestCreateTableSql case trying to create a column named "primary", I'm not sure it is intentionally or not, but this will not work in mysql, unless we wrap the talbe or column name with back quotes.
but the base dialect do not give a chance to wrap a table|column name with back quotes which means every method in it have to be rewritten for mysql dialect to support keyword table/columns.
What should I do?
Can we provide two methods for unique and non-unique index, like "Add" and "AddUnique", and remove the bool parameter. because pass bool parameter is harder to read.
And if no columns parameter is passed in, the index name will be considered as the single column name. this way we only need to pass in one parameter most of the time.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.