mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-01 15:04:11 +02:00
Added table.update(pk, ..., alter=True)
This commit is contained in:
parent
5225dbb89c
commit
4ab8d46b03
4 changed files with 40 additions and 6 deletions
|
|
@ -6,12 +6,12 @@ from sqlite_utils.db import (
|
|||
NoObviousTable,
|
||||
ForeignKey,
|
||||
)
|
||||
from sqlite_utils.utils import sqlite3
|
||||
import collections
|
||||
import datetime
|
||||
import json
|
||||
import pathlib
|
||||
import pytest
|
||||
import sqlite3
|
||||
|
||||
from .utils import collapse_whitespace
|
||||
|
||||
|
|
|
|||
|
|
@ -44,3 +44,23 @@ def test_update_invalid_pk(fresh_db, pk, update_pk):
|
|||
table.update(update_pk, {"v": 2})
|
||||
|
||||
|
||||
def test_update_alter(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
rowid = table.insert({"foo": "bar"}).last_pk
|
||||
table.update(rowid, {"new_col": 1.2}, alter=True)
|
||||
assert [{"foo": "bar", "new_col": 1.2}] == list(table.rows)
|
||||
# Let's try adding three cols at once
|
||||
table.update(
|
||||
rowid,
|
||||
{"str_col": "str", "bytes_col": b"\xa0 has bytes", "int_col": -10},
|
||||
alter=True,
|
||||
)
|
||||
assert [
|
||||
{
|
||||
"foo": "bar",
|
||||
"new_col": 1.2,
|
||||
"str_col": "str",
|
||||
"bytes_col": b"\xa0 has bytes",
|
||||
"int_col": -10,
|
||||
}
|
||||
] == list(table.rows)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue