mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-08 09:34:08 +02:00
Added create_index(..., if_not_exists=True), refs #14
This commit is contained in:
parent
0c6745b70f
commit
7784b924a1
3 changed files with 18 additions and 3 deletions
|
|
@ -1,9 +1,10 @@
|
|||
from sqlite_utils.db import Index, Database
|
||||
import collections
|
||||
import datetime
|
||||
import json
|
||||
import pathlib
|
||||
import pytest
|
||||
import json
|
||||
import sqlite3
|
||||
|
||||
try:
|
||||
import pandas as pd
|
||||
|
|
@ -188,6 +189,17 @@ def test_create_index_unique(fresh_db):
|
|||
)
|
||||
|
||||
|
||||
def test_create_index_if_not_exists(fresh_db):
|
||||
dogs = fresh_db["dogs"]
|
||||
dogs.insert({"name": "Cleo", "twitter": "cleopaws", "age": 3, "is_good_dog": True})
|
||||
assert [] == dogs.indexes
|
||||
dogs.create_index(["name"])
|
||||
assert 1 == len(dogs.indexes)
|
||||
with pytest.raises(sqlite3.OperationalError):
|
||||
dogs.create_index(["name"])
|
||||
dogs.create_index(["name"], if_not_exists=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data_structure",
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue