
    11ia                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJr  SSKJr  S rS\\4S\\4SS S	 4S
S S 4S\\4S.r " S S\R"                  5      r " S S\R"                  5      rS rSS.S\R*                  S\S\S\R.                  \   S\S\R2                  \   4S jjrS\R*                  S\S\R8                  \R:                  \   \R.                  4   4S jr\	R>                   " S S 5      5       r \	R>                   " S! S"\!5      5       r" S(S#\
R                  S$\R2                  \   S\R:                  \"   4S% jjr# " S& S'\!5      r$g))a(  
SQLite as alternative storage backend for a TableGroup's data.

For the most part, translation of a TableGroup's tableSchema to SQL works as expected:

- each table is converted to a `CREATE TABLE` statement
- each column specifies a column in the corresponding `CREATE TABLE` statement
- `foreignKey` constraints are added according to the corresponding `tableSchema` property.

List-valued foreignKeys are supported as follows: For each pair of tables related through a
list-valued foreign key, an association table is created. To make it possible to distinguish
multiple list-valued foreign keys between the same two tables, the association table has
a column `context`, which stores the name of the foreign key column from which a row in the
assocation table was created.

Other list-valued columns work in two different ways: If the atomic datatype is `string`, the
specified separator is used to create a concatenated string representation in the database field.
Otherwise, the list of values is serialized as JSON.

SQL table and column names can be customized by passing a translator callable when instantiating
a :class:`Database`.

SQLite support has the following limitations:

- regex constraints on strings (as specified via a :class:`csvw.Datatype`'s format attribute) are
  not enforced by the database.
    N)	DATATYPES)
TableGroupc                     U $ N ss    A/home/james-whalen/.local/lib/python3.13/site-packages/csvw/db.pyidentityr   ,   s    H    TEXTINTEGERc                 "    U c  U $ [        U 5      $ r   )intr   s    r
   <lambda>r   ;   s    qy!,c!f,r   c                 "    U c  U $ [        U 5      $ r   )boolr   s    r
   r   r   <   s    qy!-d1g-r   REALc                 "    U c  U $ [        U 5      $ r   )floatr   s    r
   r   r   ?   s    qy!.eAh.r   c                 8    U c  U $ [         R                  " U 5      $ r   )decimalDecimalr   s    r
   r   r   @   s    qy!8gooa&88r   BLOB)stringintegerbooleanr   	hexBinaryc                   H    \ rS rSrSS\S\R                  \   S\4S jjrSrg)	SchemaTranslatorH   Ntablecolumnreturnc                     g r   r   )selfr"   r#   s      r
   __call__SchemaTranslator.__call__I       r   r   r   )	__name__
__module____qualname____firstlineno__strtypingOptionalr'   __static_attributes__r   r   r
   r    r    H   s*    c 6??3+? 3  r   r    c                   &    \ rS rSrS\S\4S jrSrg)ColumnTranslatorM   r#   r$   c                     g r   r   )r&   r#   s     r
   r'   ColumnTranslator.__call__N   r)   r   r   N)r*   r+   r,   r-   r.   r'   r1   r   r   r
   r3   r3   M   s    s s r   r3   c                  2    SR                  S U  5       5      $ )N,c              3   D   #    U  H  nS R                  U5      v   M     g7f)z`{0}`N)format).0names     r
   	<genexpr>quoted.<locals>.<genexpr>S   s     ;UTGNN4((Us    )join)namess    r
   quotedrA   R   s    88;U;;;r   Fsingledb	translater"   keysrowsrC   c                |   U(       aq  SR                  [        U" U5      5      [        U Vs/ s H
  oa" X&5      PM     sn6 SR                  U Vs/ s H  nSPM     sn5      5      n U R                  X5        ggs  snf s  snf !   U(       d  U H  n	[	        XX#U	SS9  M      g[        U5        [        U5        e = f)a  
Insert a sequence of rows into a table.

:param db: Database connection.
:param translate: Callable translating table and column names to proper schema object names.
:param table: Untranslated table name.
:param keys: Untranslated column names.
:param rows: Sequence of rows to insert.
:param single: Flag signaling whether to insert all rows at once using `executemany` or one at     a time, allowing for more focused debugging output in case of errors.
z"INSERT INTO {0} ({1}) VALUES ({2})r8   ?TrB   N)r:   rA   r?   executemanyinsertprint)
rD   rE   r"   rF   rC   rG   k_sqlrows
             r
   rK   rK   V   s    " 2999U#$$7$QYu($78HH4(4ac4()+		NN3%  8(	C2%s4H   c
ds   A:A?'B B;$B;r$   c                     U R                  SR                  [        U5      5      5      nUR                   Vs/ s H  o3S   PM	     nnU[	        UR                  5       5      4$ s  snf )NzSELECT * FROM {0}r   )executer:   rA   descriptionlistfetchall)rD   r"   cudcolss        r
   selectrY   x   sU    	'..ve}=	>B..).QaD.D)bkkm$$$ *s   A#c                   b   \ rS rSrSr\R                  " 5       r\R                  " SS S9r\R                  " SS9r	\R                  " SS9r
\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9rS	 rS
\S\R$                  \   4S jrS
\S\4S jrSrg)ColSpec~   z]
A `ColSpec` captures sufficient information about a :class:`csvw.Column` for the DB schema.
r   c                     U (       a  U $ S$ )Nr   r   r   s    r
   r   ColSpec.<lambda>   s    1a>R(>Rr   )default	converterNr_   Fc                 d   U R                   [        ;   a'  [        U R                      u  U l        U l        U l        OKSU l        [
        U R                      R                  U l        [
        U R                      R                  U l        U R                  (       a  U R                  S:w  a  SU l        g g g )Nr   )		csvw_typeTYPE_MAPdb_typeconvertreadr   	to_string	to_python	separatorr&   s    r
   __attrs_post_init__ColSpec.__attrs_post_init__   s|    >>X%4<T^^4L1DL$,	!DL$T^^4>>DL!$..1;;DI>>dllf4!DL 5>r   rE   r$   c                 t   U R                   (       d  gU R                   U" U R                  5      p2/ nUR                  c  UR                  b  SSS.R	                  U R
                  5      nUR                  b]  U(       a,  UR                  SR                  X2R                  U5      5        O*UR                  SR                  X2R                  5      5        UR                  b^  U(       a-  UR                  SR                  X2R                  U5      5        GOUR                  SR                  X2R                  5      5        O[        S	 UR                  UR                  UR                  4 5       5      (       a  UR                  (       a*  UR                  S
R                  X2R                  5      5        UR                  (       a*  UR                  SR                  X2R                  5      5        UR                  (       a*  UR                  SR                  X2R                  5      5        SR                  U5      $ )z
We try to convert as many data constraints as possible into SQLite CHECK constraints.

:param translate: Callable to translate column names between CSVW metadata and DB schema.
:return: A string suitable as argument of an SQL CHECK constraint.
Ndatedatetime)ro   rp   z{2}(`{0}`) >= {2}('{1}')z`{0}` >= {1}z{2}(`{0}`) <= {2}('{1}')z`{0}` <= {1}c              3   (   #    U  H  oS Lv   M
     g 7fr   r   )r;   ccs     r
   r=    ColSpec.check.<locals>.<genexpr>   s     O*NB4*Ns   zlength(`{0}`) = {1}zlength(`{0}`) >= {1}zlength(`{0}`) <= {1}z AND )csvwr<   minimummaximumgetrc   appendr:   anylength	minLength	maxLengthr?   )r&   rE   ccnameconstraintsfuncs         r
   checkColSpec.check   s    yy99i		25II!qyy'<& c$..!  yy$&&'A'H'HPYPY[_'`a&&~'<'<UII'NOyy$&&'A'H'HPYPY[_'`a&&~'<'<UII'NOO188Q[[!++*NOOOxx""#8#?#?xx#PQ{{""#9#@#@#TU{{""#9#@#@#TU||K((r   c                     U R                  U5      nSR                  U" U R                  5      U R                  U R                  (       a  SOSU(       a  SR                  U5      5      $ S5      $ )Nz`{0}` {1}{2}{3}z	 NOT NULL z CHECK ({0}))r   r:   r<   re   required)r&   rE   _checks      r
   rO   ColSpec.sql   s`    I& ''dii LL==Kb-3N!!&)	= 	= :<	= 	=r   )rf   re   rg   )r*   r+   r,   r-   __doc__attribr<   rc   rj   re   rf   rg   r   rt   rl   r3   r/   r0   r.   r   rO   r1   r   r   r
   r[   r[   ~   s     779D4RSI%Iggd#Gggd#G774 Dwwu%H774 D"!)/ !)FOOC4H !)F=- =# =r   r[   c                      \ rS rSrSr\R                  " 5       r\R                  " \R                  " \	5      S9r
\R                  " \R                  " \	5      S9r\R                  " \R                  " \R                  5      S9r\R                  " SS9r\ SS\R$                  S\R(                  \   SS 4S jj5       r\SS	 j5       rS
\S\4S jrSrg)	TableSpec   a  
A `TableSpec` captures sufficient information about a :class:`csvw.Table` for the DB schema.

.. note::

    We support "light-weight" many-to-many relationships by allowing list-valued foreign key
    columns in CSVW. In the database these columns are turned into an associative table, adding
    the name of the column as value a `context` column. Thus, multiple columns in a table my be
    specified as targets of many-to-many relations with the same table.

    .. seealso:: `<https://en.wikipedia.org/wiki/Associative_entity>`_
ra   Nr"   drop_self_referential_fksr$   c                    U " UR                   UR                  R                  S9nUR                  R                   Vs1 s H!  oDR                  (       d  M  UR
                  iM#     nnUR                  R                   GH   nUR                  R                  (       a  M!  [        UR                  5      S:X  GaA  UR                  S   U;   Ga-  [        UR                  R                  5      S:X  d?   SR                  UR                  R                  UR                  R                  5      5       eUR                  (       a  [        UR                  5      S:X  d    SR                  UR                  5      5       e[        R!                  UR                  UR                  S   UR                  R                  R"                  UR                  R                  S   5      UR$                  UR                  S   '   GM|  U(       a1  UR                  R                  R"                  UR                  :X  a  GM  UR&                  R)                  [+        UR                  5      UR                  R                  R"                  [+        UR                  R                  5      45        GM#     UR                  R                   H  nUR
                  UR$                  ;  d  M  UR-                  S5      nUR                  R)                  [/        UR
                  U(       a  UR0                  OUUR-                  S5      UR-                  S5      UR-                  S5      S	95        M     U$ s  snf )
a  
Create a `TableSpec` from the schema description of a `csvw.metadata.Table`.

:param table: `csvw.metadata.Table` instance.
:param drop_self_referential_fks: Flag signaling whether to drop self-referential foreign         keys. This may be necessary, if the order of rows in a CSVW table does not guarantee         referential integrity when inserted in order (e.g. an eralier row refering to a later one).
:return: `TableSpec` instance.
)r<   primary_key   r   z)Composite key {0} in table {1} referencedzSTable {0} referenced by list-valued foreign key must have non-composite primary keydatatyperj   r   )r<   rc   rj   r   rt   )
local_nametableSchema
primaryKeycolumnsrj   headerforeignKeys	referenceschemaReferencelencolumnReferencer:   resourcer   r<   r   association_tabler   many_to_manyforeign_keysrx   sortedinheritr[   base)clsr"   r   specr}   list_valuedfkr   s           r
   from_table_metadataTableSpec.from_table_metadata   s    ((e6G6G6R6RS).):):)B)BR)BAkkxqxx)BR##//B<<///r))*a/B4F4Fq4I[4Xr||;;<A 3CJJLL88LL1133A  ++D4D4D0E0J 8&&,fTYY&78J @I?Z?Z		((+--4444Q7	@D%%b&8&8&;< 48M8M8T8TX\XaXa8a%%,,r112--44r||;;<. ' 00 ""**Axxt00099Z0##G/7hmmXii4YYz2:.%  + G Ss   MMc                 r   [        SR                  X5      5      n[        SR                  X45      5      nUR                  UR                  :X  a*  U=R                  S-  sl        U=R                  S-  sl        U " SR                  X5      XV[        S5      /UR                  /X/4UR                  /X4/4/S9$ )a  
List-valued foreignKeys are supported as follows: For each pair of tables related through a
list-valued foreign key, an association table is created. To make it possible to distinguish
multiple list-valued foreign keys between the same two tables, the association table has
a column `context`, which stores the name of the foreign key column from which a row in the
assocation table was created.
z{0}_{1}_1_2context)r<   r   r   )r[   r:   r<   )r   atableapkbtablebpkafkbfks          r
   r   TableSpec.association_table	  s     i&&v34i&&v3488sxxHHHHHH!!&1wy12((VU+((VU+
 	
r   rE   c                    [         R                  " XR                  5      nU R                   Vs/ s H  o3R	                  U5      PM     nnU R
                  (       aF  UR                  SR                  [        U R
                   Vs/ s H
  oR" U5      PM     sn6 5      5        U R                   Ho  u  pgnUR                  SR                  [        U Vs/ s H
  oR" U5      PM     sn6 [        U" U5      5      [        U Vs/ s H
  oQ" Xu5      PM     sn6 5      5        Mq     SR                  U" U R                  5      SR                  U5      5      $ s  snf s  snf s  snf s  snf )zC
:param translate:
:return: The SQL statement to create the table.
zPRIMARY KEY({0})z6FOREIGN KEY({0}) REFERENCES {1}({2}) ON DELETE CASCADEz,CREATE TABLE IF NOT EXISTS `{0}` (
    {1}
)z,
    )	functoolspartialr<   r   rO   r   rx   r:   rA   r   r?   )	r&   rE   col_translatecolclausesr}   r   refrefcolss	            r
   rO   TableSpec.sql   s6   
 ")))YY?59\\B\c77=)\BNN-44V,0,<,<=,<q-",<=6? @ A $ 1 1BWNNSZZ262aq)267y~&G<Gq3*G<=? @ !2
 @FFdii ).."9; 	; C > 7<s   EEE E!r   T)r$   r   )r*   r+   r,   r-   r   r   r   r<   FactoryrT   r   r   collectionsOrderedDictr   r   classmethodrt   Tabler/   r0   r   r   r   r    r.   rO   r1   r   r   r
   r   r      s     779Dggdll401G774<<#56L774<<0G0G#HIL''$'K PT0#'::07=t7L0Xc0 0d 
 
,;- ;# ;r   r   tgr   c                 v  ^^ 0 nU R                   R                  5        HW  u  nm[        R                  TUS9nXBUR                  '   UR
                  R                  5        H  nXRUR                  '   M     MY     [        R                  " 5       mSnU(       ax  US:  ar  US-  n[        UR                  5       5       HA  m[        UU4S jUT   R                   5       5      (       d  M-  UR                  T5      TT'     O   U(       a  US:  a  Mr  U(       a  [        S5      e[        TR                  5       5      $ )a  
Convert the table and column descriptions of a `TableGroup` into specifications for the
DB schema.

:param tg: CSVW TableGroup.
:param drop_self_referential_fks: Flag signaling whether to drop self-referential foreign     keys. This may be necessary, if the order of rows in a CSVW table does not guarantee     referential integrity when inserted in order (e.g. an eralier row refering to a later one).
:return: A pair (tables, reference_tables).
r   r   d   r   c              3   P   >#    U  H  oS    T;   =(       d    US    T:H  v   M     g7f)r   Nr   )r;   r   orderedr"   s     r
   r=   schema.<locals>.<genexpr>P  s*     `E_cFg%9#a&E/9E_s   #&z7there seem to be cyclic dependencies between the tables)	tabledictitemsr   r   r<   r   valuesr   r   rT   rF   allr   pop
ValueError)	r   r   tablestnametatir   r"   s	          @@r
   schemar   3  s
    F**,u))-F * Hqvv..'')B 277O *	 - %%'G	A QW	Q&++-(E`VE]E_E_```!'E!2	 ) QW RSS !!r   c            
          \ rS rSrSr   SS\S\R                  \R                  \	R                  \4      S\R                  \   S\R                  \   4S jjrSS	 jr\S
\R"                  \\4   4S j5       r\SS\S\R                  \   S
\4S jj5       rS
\R                  \R.                  \R2                  4   4S jrS
\4S jrS\S\S
\R                  \   4S jrS
\R                  \R<                  \   \S4   4S jrS
\R"                  \\R<                  \R@                     4   4S jr!S r"SS jr#SSSS.S jr$Sr%g) DatabaseiZ  a{  
Represents a SQLite database associated with a :class:`csvw.TableGroup` instance.

:param tg: `TableGroup` instance defining the schema of the database.
:param fname: Path to which to write the database file.
:param translate: Schema object name translator.
:param drop_self_referential_fks: Flag signaling whether to drop or enforce self-referential     foreign-key constraints.

.. warning::

    We write rows of a table to the database sequentially. Since CSVW does not require ordering
    rows in tables such that self-referential foreign-key constraints are satisfied at each row,
    we don't enforce self-referential foreign-keys by default in order to not trigger "false"
    integrity errors. If data in a CSVW Table is known to be ordered appropriately, `False`
    should be passed as `drop_self_referential_fks` keyword parameter to enforce
    self-referential foreign-keys.
Nr   fnamerE   r   c                     U=(       d    [         R                  U l        U(       a  [        R                  " U5      OS U l        U R                  XS9  S U l        g Nr   )r   name_translatorrE   pathlibPathr   init_schema_connection)r&   r   r   rE   r   s        r
   __init__Database.__init__m  sC     #>h&>&>,1W\\%(t
Qr   c                 t    Xl         U R                   (       a  [        U R                   US9U l        g / U l        g r   )r   r   r   )r&   r   r   s      r
   r   Database.init_schemay  s1    MQWW GG/HJZ\ 	r   r$   c                 Z    U R                    Vs0 s H  oR                  U_M     sn$ s  snf r   )r   r<   )r&   r   s     r
   tdictDatabase.tdict~  s$    #';;/;a	;///s   (r"   r#   c                     U=(       d    U $ )a6  
A callable with this signature can be passed into DB creation to control the names
of the schema objects.

:param table: CSVW name of the table before translation
:param column: CSVW name of a column of `table` before translation
:return: Translated table name if `column is None` else translated column name
r   )r"   r#   s     r
   r   Database.name_translator  s     r   c                    U R                   (       a=  [        R                  " [        R                  " [        U R                   5      5      5      $ U R                  (       d  [        R                  " S5      U l        U R                  $ )Nz:memory:)r   
contextlibclosingsqlite3connectr.   r   rk   s    r
   
connectionDatabase.connection  sQ    ::%%gooc$**o&FGG&z:Dr   c                    Ub  SR                  U5      nOSnSR                  [        U R                  UR                  UR                  S   R                  5      5      [        U R                  UR                  UR                  S   R                  5      5      [        U R                  UR                  5      5      U5      nUR                  U5      nUR                  5        VVV	s0 s HQ  nUS   [        US   R                  5       US   R                  S5      5       VV	s/ s H  u  pUc  X4OUPM     sn	n_MS     sn	nn$ s  sn	nf s  sn	nnf )NzWHERE context = '{0}'r   zgSELECT {0}, group_concat({1}, ' '), group_concat(COALESCE(context, ''), '||')
FROM {2} {3} GROUP BY {0}r   r      z||)	r:   rA   rE   r<   r   rR   rU   zipsplit)
r&   rD   r"   r   context_sqlrO   rV   rrM   vs
             r
   select_many_to_manyDatabase.select_many_to_many  s/   188AKK#Vt~~ejj%--2B2G2GHIt~~ejj%--2B2G2GHIt~~ejj12	 	 ZZ_ NP[[]\MZ aD"1Q4::<1D1ABDBtq %_A6!3BD DMZ\ 	\D\s   '<E
#E7E
E
r   r~   c                     U R                    Hi  nU R                  U5      U:X  d  M  U R                   U   R                   H2  nU R                  X4R                  5      U:X  d  M$  UR                  s  s  $    Mk     g)zU
:return: separator for the column specified by db schema names `tname` and `cname`.
N)r   rE   r   r<   rj   )r&   r   r~   r<   r   s        r
   rj   Database.separator  s[     JJD~~d#u,::d+33C~~dHH5>"}}, 4 r   c                 j    U R                  X5      nU(       a  U=(       d    SR                  U5      $ U$ )Nr   )rj   r   )r&   r   r~   valueseps        r
   split_valueDatabase.split_value  s,    nnU*+.""3'9E9r   c           
         [         R                  " [        5      nU R                  5        nU R                  R
                   GHf  n0 0 [         R                  " [        5      penU R                  U   nUR                   GH  nUR                  [        /X@R                  X8R                  5      '   UR                  [        ;   a5  [        UR                     S   X@R                  X8R                  5         S'   O;[        UR                     R                  X@R                  X8R                  5         S'   UR                   (       d  M  UR                  S:X  a*  UR                   XPR                  X8R                  5      '   GM  SXPR                  X8R                  5      '   GM"     UR"                  R%                  5        HD  u  pU R'                  X)U5      R%                  5        H  u  pXU
   U R                  X85      '   M     MF     [)        X R                  U5      5      u  pU GH  n[         R*                  " 5       n[-        X5       H  u  nnUU;   a{  Uc  SUU'   M  U(       d  / UU'   M$  UU   S:X  a  [.        R0                  " U5      UU'   MH  U=(       d    SR3                  UU   5       Vs/ s H  nUU   S   " U5      PM     snUU'   M  Ub  UU   S   " U5      OSUU'   M     UR4                  (       a9  [7        UR4                  5      S:X  a   XR                  X7R4                  S   5         OSn
UR9                  UR"                   Vs0 s H  nU/ _M     sn5        UR9                  UR;                  U
0 5      5        XR                  U5         R=                  U5        GM     GMi     SSS5        U$ s  snf s  snf ! , (       d  f       U$ = f)z
:return: A `dict` where keys are SQL table names corresponding to CSVW tables and values         are lists of rows, represented as dicts where keys are the SQL column names.
r   r   r   jsonNr   r   )r   defaultdictrT   r   r   r   dictr   r   r<   r   rE   rc   rd   r   ri   rj   r   r   r   rY   r   r   r  loadsr   r   r   updaterw   rx   )r&   resconnr   rf   sepsrefsr"   r   r   pkr   rX   rG   rP   rW   rM   v_s                     r
   rg   Database.read  s   
 %%d+__$**
 ')"k.E.Ed.Kt

5) !==C@C(?SGNN5((;<}}0FNs}}F]^_F`uhh ?@C &cmm4>>  uhh ?@C}}}==H4DGMMDxx!@ADJDxx!@A )  %11779GC!%!9!9$C!H!N!N!P?@R!;< "Q  : $D..*?@
C#//1A #D19 y'+!%&')!!%aF!2'+zz!}!EFW"OOTXYZT[D\']D\b
1b(9D\']!78}71:a=#3$AaD !/ !,,U5F5F1G11L >>%1B1B11EFGRV HHU-?-?@-?ae-?@AHHTXXb"-.u-.55a8%  9 + ` 
 (^
 A[ ` 
s3   DOE'O-N7BON<AO7
O
Oc                     X24$ )an  
Context for association tables is created calling this method.

Note: If a custom value for the `context` column is created by overwriting this method,
`select_many_to_many` must be adapted accordingly, to make sure the custom
context is retrieved when reading the data from the db.

:param table:
:param column:
:param fkey:
:return: a pair (foreign key, context)
r   )r&   r"   r#   fkeys       r
   association_table_context"Database.association_table_context  s     |r   Fc                 ^    U R                   " SUUUS.U R                  R                  5       D6$ )Nforce
_exists_ok_skip_extrar   )writer   rg   )r&   _forcer  r  s       r
   write_from_tgDatabase.write_from_tg  s5    zz !# gglln	 	r   r  c                  ^ U R                   (       aK  U R                   R                  5       (       a,  U(       d  [        S5      eU R                   R                  5         U R	                  5        nU R
                   H+  nUR                  UR                  U R                  S95        M-     UR                  S5        UR                  5         [        R                  " [        5      nU R
                   GH  nUR                  U;  a  M  / / pUR                   Vs0 s H  oR                  U_M     nn[        XHR                     5       GH  u  pUR                   (       a*  [#        UR                   5      S:X  a  XR                   S      OSn/ nUR%                  5        GH  u  nnUUR&                  ;   a  U(       d   eUR&                  U   n[)        UR                  /UR                   Vs/ s H  oR                  PM     sn-   5      nU=(       d    /  H0  nU R+                  UUU5      u  nnUU   R-                  UUU45        M2     M  UU;  a#  U(       a  M  [        SR/                  U5      5      eUU   m[1        U[        5      (       aV  TR2                  S:X  a/  TR4                  =(       d    S	R7                  U4S
 jU 5       5      nO-[8        R:                  " U5      nOUb  TR=                  U5      OSnUS:X  a  U
R-                  TR                  5        UR-                  U5        GM     U	R-                  [)        U5      5        GM     [?        XPR                  UR                  U
/U	Q76   GM     UR%                  5        H$  u  nn	[?        XPR                  US   USS /U	Q76   M&     UR                  5         SSS5        gs  snf s  snf ! , (       d  f       g= f)zk
Creates a db file with the core schema.

:param force: If `True` an existing db file will be overwritten.
z3db file already exists, use force=True to overwrite)rE   zPRAGMA foreign_keys = ON;r   r   Nz$unspecified column {0} found in datar   ;c              3   X   >#    U  H  nTR                  U5      =(       d    S v   M!     g7f)r   N)rf   )r;   vvr   s     r
   r=   !Database.write.<locals>.<genexpr>6  s&      DKHI"B(=2(=s   '*) r   existsr   unlinkr   r   rR   rO   rE   commitr   r  rT   r<   r   	enumerater   r   r   r   tupler  rx   r:   
isinstancerc   rj   r?   r  dumpsrf   rK   )r&   r  r  r  r   rD   r"   r
  r   rG   rF   r}   rX   r   rP   r  r   rM   r   r   atkeyr  r  r   r   s                           @r
   r  Database.write  s    ::$**++-- !VWW

!!#__"

599t~~9>? % JJ23IIK**40D[[66&d+,9959a	95'ff6FA==S-?1-D ]]1-.JN F #		1.#%I2!"!2B$)277)rzz6Rz!vvz6R*R$SE ()wBw040N0NqRSUW0Xg $U 2 2Bg3F G (/  !}#.$,*4(N(U(UVW(X+Z %Z"&q'C)!T22#&==H#<),)=#(C(C DKHIDK )KA )-

1A67mCKKN Av $CHH 5"MM!,; !,< KKf.E 7F r>>1664?$?Q !T  $zz|tr>>58U12YFF  , IIKk  6 7S+ s-   .B*OO.B<O*O?F>O
O
O)r   r   r   r   rE   )NNTr   r   )FFF)&r*   r+   r,   r-   r   r   r/   r0   Unionr   r   r.   r    r   r   r   propertyDictr   r   staticmethodr   r   
Connectionr   r   r   r  r   rj   Listr   r   rg   r  r  r  r1   r   r   r
   r   r   Z  s   * GK;??C
 
  ??6<<c0A#BC
  '78	
 
 (.t'<
 ]
 0v{{3	>2 0 0 
s 
FOOC,@ 
C 
 
 FLL););Z=O=O)OP  \ \"-s -3 -6??33G -:&,,v{{3?OQTVZ?Z2[ :6fkk#v{{63E3E'F"FG 6p  #u% A Ar   r   r   )%r   r  r/   r   r   r   r   r   r   r   rt   csvw.datatypesr   csvw.metadatar   r   rd   Protocolr    r3   rA   r-  r.   SequencerT   r0   r   rK   Tupler.  rY   r	   r[   objectr   r   r   r   r   r
   <module>r5     s  6           $ $ 	
 	
 	,-/
 	.8:
 	#0v 
v 
< ,1w!! & % 	
 ??4(D%w!! %# %&,,v{{3?OQWQ`Q`?`2a % @= @= @=F m; m; m;b ?C$"t $"&,ood&;$"GM{{S\G]$"Nkv kr   