5 votes

Fortnightly Programming Q&A Thread

General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.

Don't forget to format your code using the triple backticks or tildes:

Here is my schema:

```sql
CREATE TABLE article_to_warehouse (
  article_id   INTEGER
, warehouse_id INTEGER
)
;
```

How do I add a `UNIQUE` constraint?

1 comment

  1. Gyrfalcon
    Link
    Hello! I've been getting back into personal projects by trying out Julia on some old Advent of Code problems and retooling some personal projects. I did a writeup of a question I have that really...

    Hello! I've been getting back into personal projects by trying out Julia on some old Advent of Code problems and retooling some personal projects. I did a writeup of a question I have that really gets at moving from object oriented languages (Python/C++) to Julia, where multiple dispatch is the name of the game, along with grokking the nature of including other source files in Julia. If you know anything about that, I'd love it if you could post an answer here, or on the Julia forum. I'll also copy the post I made here for reference:

    Hello! I am a newcomer to Julia and I am trying to recreate something that I worked a bit on in Python in Julia, because I think Julia will be the better language overall for numerical performance. However, I am trying to do something that I am not sure Julia is suited for before I can get to that numerical aspect.

    The code needs to interact with several outside sources of data, like databases, web APIs, etc. What I would like is for a configuration file to be able to define which files to import for each of these sources. Then, the program will import those source files and use the functions within to download data, store it away, etc. In Python I would do this with an abstract base class, and dynamically import the module based on the name saved in the configuration file. In Julia, I am not so sure. It seems there are a few options possible with metaprogramming, but I am not sure they fit exactly into what I imagine. Maybe something like the following as a minimum (but not working!) example would help:

    # Main file
    include("ConfigImport.jl")
    
    function main()
        imported_file = ConfigImport.import_config() # where imported file is a reference to OtherFile
        imported_file.do_stuff()
    end
    
    main()
    
    # ConfigImport.jl
    
    module ConfigImport
    
    using TOML
    
    function import_config()
    
    config_data = nothing
        try
            config_data = TOML.parsefile("config/config.toml")
    
        catch e
            if isa(e, SystemError)
                println("It appears the config file is missing!")
            elseif isa(e, TOML.ParserError)
                println("It appears there is something wrong with the format of the config file!")
            else
                throw(e)
            end
        end
    
        include(config_data["OtherFile"] * ".jl")
        return Symbol(config_data["OtherFile"])
    end
    end
    
    # OtherFile.jl
    
    module OtherFile
    
    function do_stuff()
        println("Doing some stuff!")
    end
    
    end
    

    I feel like there has to be a better design pattern or a use of macros to accomplish what I am trying to do, I just have no idea what that might be.