Code Monkey home page Code Monkey logo

Comments (4)

vmihailenco avatar vmihailenco commented on July 22, 2024 1

Actually it is the opposite. pg.DB can be used concurrently and it manages connections behind the scene, so you don't have to to call Close manually. But sql.DB requires you to manually call rows.Close to ensure that connection can be freed.

pg.DB.Close closes the client and all connections in the client pool. You should call it when app is about to exit or you want to connect to another database. I will remove Close from examples to avoid confusion.

from pg.

medvednikov avatar medvednikov commented on July 22, 2024

Wow you are right.

I was using gorp, and it called rows.Close() for me, so I didn't realize it was necessary.

That's great! Thanks a lot for this great library. I'm migrating my application from gorp to pg. After playing with pgx and some other libs I've come to conclusion that yours is the best one, hands down.

Two things I was missing and had to implement manually are a way to insert an entire object and nil receivers:

newUser := &User{Name:"Bob", Age:20}
Insert("INSERT INTO User", newUser)

var u *User
QueryOne(&u, "SELECT * FROM User LIMIT 1")

The nil receiver thing means less typing if you need a pointer, and it's also easier to check if nothing was found by simply comparing the receiver to nil afterwards.

Would you be willing to accept these 2 features if I submitted a pull request?

from pg.

vmihailenco avatar vmihailenco commented on July 22, 2024

The nil receiver thing means less typing if you need a pointer, and it's also easier to check if nothing was found by simply comparing the receiver to nil afterwards.

This is the desired behaviour and I will accept a PR implementing it. Though keep in mind that QueryOne returns ErrNoRows when there are no rows.

newUser := &User{Name:"Bob", Age:20}
Insert("INSERT INTO User", newUser)

Adding Insert means that we also need Update and Delete. Then we find that we want to support more and more SQL features in Insert/Update/Delete until we fully support all SQL syntax. I don't want to go this route.

from pg.

medvednikov avatar medvednikov commented on July 22, 2024

Ok great, I'll submit a pull request before Tuesday.

Thanks!

from pg.

Related Issues (20)

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.