1. 7
  1.  

  2. 7

    The way I expected this to work from the README and name is that it wrapped the PostgreSQL C code to run the lot in-memory, or something along those lines.

    But looking at the source this is not how it works at all: NewDatabase() fetches a binary from https://repo1.maven.org, extracts it to a temporary path, and runs pg_ctl start with exec.Command(). Nothing is “embedded” in any way I would use the word, and it’s not even easy to implement that in the current version as it expects to read stuff from the filesystem (rather than an io.Reader or whatnot). It’s also just an unmodified PostgreSQL as far as I can tell.

    Useful for some things? I guess? Maybe? But very limited. I’d just run PostgreSQL.

    Also, this was so obviously written by a Java developer.

    1. 3

      That’s kind of nasty. Why not just use a shell script that makes and runs a docker container?

      1. 4

        that would depend on docker, whereas the goal of this project is to depend only on the Go standard library.

      2. 3

        It is possible to run a PostgreSQL database in memory which is what I expected to find. I agree this doesn’t really fit the “embedded” idea at all.

        1. 2

          Any links to running a postgres database in memory for real?

      3. 1

        I’m curious. what is the use case that is not covered by other user process databases like sqlite3?

        1. 4

          It’s literally postgres. Sqlite and postgres aren’t the same thing. Postgres has many more datatypes and builtin support for cool json stuff. If you only wanted to use sqlite for testing you’d have to either avoid using some datatypes or use an orm that will polyfill missing types and functions.

          Edit: sqlite also doesn’t support altering tables. The list of differences just goes on and on. What’s the value in have test specific code? (I’ve definitely done this before too)

          1. 3

            Just pointing out that SQLite definitely has some JSON support https://sqlite.org/json1.html#the_json_function as well as ALTER TABLE support https://sqlite.org/lang_altertable.html

            1. 1

              Yes JSON functions are available if you load the extension. But it’s not built in. Every db has lots of extensions. And even then if you’re using JSON in Postgres or MySQL you’re probably using the d->>‘x’->y syntax and that doesn’t exist in SQLite so you do need to have a transform layer before generating SQL if you want to support both.

              And yes good callout; I think it’s just that you cannot change a column type in SQLite? It’s been a bit since I was doing work on it.

              1. 4

                For go at least, modernc.org/sqlite has the JSON support fully working out of the box.

                1. 3

                  Gotcha, thanks.

                2. 2

                  Yes JSON functions are available if you load the extension. But it’s not built in.

                  I think a lot of people build their distribution of sqlite3 from the amalgamation which does have JSON support built-in.

                  e.g. immediately to hand I have macOS Monterey (SQLite v3.35.3), Arch (v3.35.5), Cygwin (v3.34.0) all have the JSON support natively. On the other hand, my NAS (SQLite v3.8.4.3 from 2014) doesn’t have it.

                  (edit: has -> have)

                  1. 2

                    Ah cool, makes sense.

              2. 2

                Title says “in application or test”, I guess I should have been more specific, I didn’t mean the test part, that was obvious to me.

              3. 1

                automating the testing of postgres queries, stored procedures, etc, that are expressed in the source code of a Go program.