Giter Site home page Giter Site logo

Comments (6)

simonw avatar simonw commented on May 20, 2024

This seems reasonable. It could look like this:

db["dogs"].add_column("instagram", str, not_null=True)
db["dogs"].add_column("is_good_dog", bool, default=True)

And this:

$ sqlite-utils add-column mydb.db dogs instagram --not-null
$ sqlite-utils add-column mydb.db dogs is_good_dog integer --default=1

from sqlite-utils.

simonw avatar simonw commented on May 20, 2024

Hmm... we need the ability to pass --not-null when we are creating a table as well.

If you attempt to add NOT NULL to a column after a table has first been created you get this error:

sqlite3.OperationalError: Cannot add a NOT NULL column with default value NULL

from sqlite-utils.

simonw avatar simonw commented on May 20, 2024

Since you can't have one without the other, I'm going with --not-null-default= and not_null_default= for the add column versions of this.

from sqlite-utils.

simonw avatar simonw commented on May 20, 2024

But what to do for creating a table?

For the Python function I could do this:

db["cats"].create({
    "id": int,
    "name": str,
    "score": int, 
    "weight": float,
}, pk="id", not_null={"weight"}, defaults={"score": 1})

The CLI tool only every creates tables as a side-effect of a sqlite-utils insert or sqlite-utils upsert. I can have them accept optional arguments, --not-null colname and --default colname value:

echo '{"name": "Cleo", "age": 4, "score": 2}' | \
  sqlite-utils insert dogs.db dogs - \
    --not-null age \
    --not-null name \
    --default score 1

from sqlite-utils.

simonw avatar simonw commented on May 20, 2024

Maybe it's time to create a sqlite-utils create-table command here too, rather than forcing people to create tables only by inserting example data.

from sqlite-utils.

simonw avatar simonw commented on May 20, 2024

@IgnoredAmbience this is now shipped in sqlite-utils 1.2 - documentation here:

from sqlite-utils.

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.