Comments (6)
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.
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.
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.
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.
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.
@IgnoredAmbience this is now shipped in sqlite-utils 1.2 - documentation here:
- https://sqlite-utils.readthedocs.io/en/latest/python-api.html#python-api-defaults-not-null
- https://sqlite-utils.readthedocs.io/en/latest/cli.html#cli-defaults-not-null
from sqlite-utils.
Related Issues (20)
- Mechanism for de-registering registered SQL functions HOT 3
- Ability to tell if a Database is an in-memory one HOT 1
- `table.transform()` should preserve `rowid` values HOT 6
- Represent compound foreign keys in table.foreign_keys output HOT 2
- Cascading DELETE not working with Table.delete(pk) HOT 1
- Feature request: sqlite-utils insert-files should be able to convert fields
- Cannot find spatialite on arm64 linux HOT 1
- Move plugin directory into documentation
- `sqlite-utils transform` removes the `AUTOINCREMENT` keyword
- Pyhton 3.12 Bug report HOT 2
- Insert fails with `Error: Python int too large to convert to SQLite INTEGER`; can we use `NUMERIC` here? HOT 1
- str and int as aliases for text and integer HOT 2
- pyright and mypy showing access error messages for basic sqlite-utils usage
- Attached database tables representable by `Table`
- `table.upsert/upsert_all` fails to write row when `not_null` is absent and the schema definition includes `not_null` HOT 3
- `.transform()` effect on triggers and indices
- Automatic JSON de-serialization
- Windows: Correct way to initialize spatialite?
- sqlite-utils command fails when used with xargs HOT 2
- Drop support for Python 3.7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlite-utils.