Coder Social home page Coder Social logo

hood's People

Contributors

aleksi avatar coocood avatar crisfole avatar diseaz avatar iragsdale avatar lbolla avatar redneckbeard avatar stefankjartansson avatar ulfnielsen 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hood's Issues

Complete sqlite3 dialect

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.

Make Hood tool more flexible

The current hood tool is too tightly tied to the config.json, make it more configurable and flexible via command line flags.

Null values cause a crash

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.

Sqlite3 Support?

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

Implement DeleteFrom method

Implement a DeleteFrom method, to allow statements like

DELETE FROM table WHERE condition

Proposed syntax:

hd.Where("a", "=", "b").DeleteFrom("table")

hood create:config fails db/config.json doesn't already exist

$ /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

can't call functions on where close

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).

aggregate functions

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?

Title case field naming

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!

Documentation: CreateTable is misleading in "Basic Example"

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

AfterGet / AfterSelect

How do you feel about adding a hook that runs after loading an entity? I use this feature (in Gorp) presently for two things:

  1. Eagerly loading relations
  2. Setting Go properties that do not map directly to a SQL data type -- for example, time.Time does not work with sqlite3 -- to work around that, in BeforeSave I set a TimeStr string field on the model, and in AfterGet I parse that property back into the time.Time field.

Although, it looks like there is no way to issue queries from the hook, so use case (1) would not apply anyway.

Loading Relations

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?

DATABASE_URL support

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.

Follow standard convention for struct tags

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.

Run migration in application.

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.

Queried results end up camelcased instead of underscored

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.

License?

Couldn't find mention of what license this is released under, please include a LICENSE file.

Thanks!

support passing slice of pointers to Find(&out) method.

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

Add quoting to dialect interface

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?

A suggestion to simplify Indexes Add method.

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.

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.