
    Pia                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ d Zdeefdeefdd d	 fd
d d fdeefdZ G d dej                  Z G d dej                  Zd Zdddej        dededej        e         dedej        e         fdZdej        dedej        ej        e         ej        f         fdZe	j         G d d                       Z e	j         G d! d"e!                      Z"	 d)d$e
j        d%ej        e         dej        e"         fd&Z# G d' d(e!          Z$dS )*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                     | S N ss    [/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/csvw/db.pyidentityr   ,   s    H    TEXTINTEGERc                 (    | | nt          |           S r   )intr   s    r
   <lambda>r   ;   s    qy!!c!ff r   c                 (    | | nt          |           S r   )boolr   s    r
   r   r   <   s    qy!!d1gg r   REALc                 (    | | nt          |           S r   )floatr   s    r
   r   r   ?   s    qy!!eAhh r   c                 2    | | nt          j        |           S r   )decimalDecimalr   s    r
   r   r   @   s    qy!!goa&8&8 r   BLOB)stringintegerbooleanr   	hexBinaryc                   :    e Zd Zddedej        e         defdZdS )SchemaTranslatorNtablecolumnreturnc                     d S r   r   )selfr!   r"   s      r
   __call__zSchemaTranslator.__call__I       r   r   )__name__
__module____qualname__strtypingOptionalr&   r   r   r
   r    r    H   sI         c 6?3+? 3      r   r    c                       e Zd ZdedefdZdS )ColumnTranslatorr"   r#   c                     d S r   r   )r%   r"   s     r
   r&   zColumnTranslator.__call__N   r'   r   N)r(   r)   r*   r+   r&   r   r   r
   r/   r/   M   s6        s s      r   r/   c                  @    d                     d | D                       S )N,c              3   @   K   | ]}d                      |          V  dS )z`{0}`N)format).0names     r
   	<genexpr>zquoted.<locals>.<genexpr>S   s.      ;;TGNN4((;;;;;;r   )join)namess    r
   quotedr:   R   s#    88;;U;;;;;;r   Fsingledb	translater!   keysrowsr<   c          
         |rd                     t                               t          fd|D              d                    d |D                                 }	 |                     ||           dS #  |s|D ]}t	          | ||d           Y dS t          |           t          |            xY wdS )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})c                 (    g | ]} |          S r   r   )r5   kr!   r>   s     r
   
<listcomp>zinsert.<locals>.<listcomp>j   s%    777QYYua((777r   r2   c                     g | ]}d S )?r   )r5   _s     r
   rD   zinsert.<locals>.<listcomp>k   s    (((ac(((r   Tr;   N)r4   r:   r8   executemanyinsertprint)r=   r>   r!   r?   r<   r@   sqlrows    ``     r
   rI   rI   V   s   "  29999U##$$77777$7778HH((4((())+ +		NN3%%%%%	  I IC2y%s4HHHHHI I I c


d s   $A< <B<B<r#   c                     |                      d                    t          |                              }d |j        D             }|t	          |                                          fS )NzSELECT * FROM {0}c                     g | ]
}|d          S )r   r   )r5   ds     r
   rD   zselect.<locals>.<listcomp>z   s    )))QAaD)))r   )executer4   r:   descriptionlistfetchall)r=   r!   cucolss       r
   selectrV   x   sX    	'..ve}}==	>	>B))".)))Dbkkmm$$$$r   c                   ^   e Zd ZdZ ej                    Z ej        dd           Z ej        d          Z ej        d          Z	 ej        d          Z
 ej        d          Z ej        d          Z ej        d          Zd Zd	ed
ej        e         fdZd	ed
efdZdS )ColSpecze
    A `ColSpec` captures sufficient information about a :class:`csvw.Column` for the DB schema.
    r   c                     | r| ndS )Nr   r   r   s    r
   r   zColSpec.<lambda>   s    1>Raa( r   )default	converterNrZ   Fc                 &   | j         t          v r&t          | j                  \  | _        | _        | _        n?d| _        t
          | j                  j        | _        t
          | j                  j        | _        | j        r| j        dk    rd| _        d S d S d S )Nr   )		csvw_typeTYPE_MAPdb_typeconvertreadr   	to_string	to_python	separatorr%   s    r
   __attrs_post_init__zColSpec.__attrs_post_init__   s    >X%%4<T^4L1DL$,		!DL$T^4>DL!$.1;DI> 	"dlf44!DLLL	" 	"44r   r>   r#   c                    | j         sdS | j          || j                  }}g }|j        |j        ddd                    | j                  }|j        `|r0|                    d                    ||j        |                     n.|                    d                    ||j                             |j        `|r0|                    d                    ||j        |                     n|                    d                    ||j                             nt          d	 |j	        |j
        |j        fD                       r|j	        r.|                    d
                    ||j	                             |j
        r.|                    d                    ||j
                             |j        r.|                    d                    ||j                             d                    |          S )a  
        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)ri   rj   z{2}(`{0}`) >= {2}('{1}')z`{0}` >= {1}z{2}(`{0}`) <= {2}('{1}')z`{0}` <= {1}c              3      K   | ]}|d uV  	d S r   r   )r5   ccs     r
   r7   z ColSpec.check.<locals>.<genexpr>   s&      OOB4OOOOOOr   zlength(`{0}`) = {1}zlength(`{0}`) >= {1}zlength(`{0}`) <= {1}z AND )csvwr6   minimummaximumgetr^   appendr4   anylength	minLength	maxLengthr8   )r%   r>   ccnameconstraintsfuncs         r
   checkzColSpec.check   s    y 	F9ii	225I!qy'<&  c$.!!  y$ P&&'A'H'HPQPY[_'`'`aaaa&&~'<'<UAI'N'NOOOy$ P&&'A'H'HPQPY[_'`'`aaaa&&~'<'<UAI'N'NOOOOO18Q[!+*NOOOOO 	Vx R""#8#?#?qx#P#PQQQ{ V""#9#@#@#T#TUUU{ V""#9#@#@#T#TUUU||K(((r   c                     |                      |          }d                     || j                  | j        | j        rdnd|rd                    |          nd          S )Nz`{0}` {1}{2}{3}z	 NOT NULL z CHECK ({0}))rz   r4   r6   r`   required)r%   r>   _checks      r
   rK   zColSpec.sql   sh    I&& ''Idi  L=0KKb-3;N!!&)))	= = 	=r   )r(   r)   r*   __doc__attribr6   r^   re   r`   ra   rb   r}   rm   rg   r/   r,   r-   r+   rz   rK   r   r   r
   rX   rX   ~   s         4799D4R4RSSSI%%%Idgd###Gdgd###G474   Dtwu%%%H474   D" " "!)/ !)FOC4H !) !) !) !)F=- =# = = = = = =r   rX   c                      e Zd ZdZ ej                    Z ej         ej        e                    Z	 ej         ej        e                    Z
 ej         ej        ej                            Z ej        d          Ze	 ddej        dej        e         dd fd            Zedd	            Zd
edefdZdS )	TableSpeca7  
    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>`_
    r\   NTr!   drop_self_referential_fksr#   c                     | |j         |j        j                  }d |j        j        D             }|j        j        D ]}|j        j        st          |j                  dk    r |j        d         |v rt          |j        j                  dk    s2J d	                    |j        j        |j        j
                              |j        rt          |j                  dk    s"J d	                    |j                              t                              |j        |j        d         |j        j
        j        |j        j        d                   |j        |j        d         <   )|r|j        j
        j        |j        k    sU|j                            t'          |j                  |j        j
        j        t'          |j        j                  f           |j        j        D ]}|j        |j        vr|                    d          }|j                            t-          |j        |r|j        n||                    d          |                    d	          |                    d          
                     |S )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.
        )r6   primary_keyc                 *    h | ]}|j         	|j        S r   )re   headerr5   rv   s     r
   	<setcomp>z0TableSpec.from_table_metadata.<locals>.<setcomp>   s!    RRRAakRqxRRRr      r   z)Composite key {0} in table {1} referencedzSTable {0} referenced by list-valued foreign key must have non-composite primary keydatatypere   r}   )r6   r^   re   r}   rm   )
local_nametableSchema
primaryKeycolumnsforeignKeys	referenceschemaReferencelencolumnReferencer4   resourcer   r6   r   association_tabler   many_to_manyforeign_keysrq   sortedr   inheritrX   base)clsr!   r   speclist_valuedfkrv   r   s           r
   from_table_metadatazTableSpec.from_table_metadata   s~    s(e6G6RSSSRR):)BRRR#/ 	 	B</ r)**a//B4Fq4I[4X4Xr|;<<AAACJJL8L13 3 BAA  + 8D4D0E0E0J0J0J&&,fTY&7&7 1K0JJ @I?Z?Z	(+-44Q7	@ @D%b&8&;<< 4 8M8TX\Xa8a8a%,,r122-4r|;<<.   
 "* 		 		Axt00099Z00##G/7EhmmXii44YYz22:..% % %    r   c                 ~   t          d                    ||                    }t          d                    ||                    }|j        |j        k    r |xj        dz  c_        |xj        dz  c_         | d                    ||          ||t          d          g|j        g||gf|j        g||gfg          S )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)r6   r   r   )rX   r4   r6   )r   atableapkbtablebpkafkbfks          r
   r   zTableSpec.association_table	  s     i&&vs3344i&&vs33448sxHHHHHHHHs!!&&11#wy112(VcU+(VcU+
 
 
 	
r   r>   c                 H   t          j        | j                  fd| j        D             }| j        r@|                    d                    t          fd| j        D                                   | j        D ]m\  }}|                    d                    t          fd|D              t                               t          fd|D                                   nd                     | j                  d	                    |                    S )	z[
        :param translate:
        :return: The SQL statement to create the table.
        c                 :    g | ]}|                               S r   )rK   )r5   colcol_translates     r
   rD   z!TableSpec.sql.<locals>.<listcomp>&  s%    BBBc377=))BBBr   zPRIMARY KEY({0})c                 &    g | ]} |          S r   r   r5   rv   r   s     r
   rD   z!TableSpec.sql.<locals>.<listcomp>)  s#    ===q--""===r   z6FOREIGN KEY({0}) REFERENCES {1}({2}) ON DELETE CASCADEc                 &    g | ]} |          S r   r   r   s     r
   rD   z!TableSpec.sql.<locals>.<listcomp>,  s#    666aq))666r   c                 (    g | ]} |          S r   r   )r5   rv   refr>   s     r
   rD   z!TableSpec.sql.<locals>.<listcomp>.  s%    <<<q3**<<<r   z,CREATE TABLE IF NOT EXISTS `{0}` (
    {1}
)z,
    )
	functoolspartialr6   r   r   rq   r4   r:   r   r8   )r%   r>   clausesr   refcolsr   r   s    `   @@r
   rK   zTableSpec.sql   sf   
 "))TY??BBBBT\BBB 	ANN-44V====D,<===6? @ @ A A A $ 1 	@ 	@BWNNSZZ666626667yy~~&&<<<<<G<<<=? ? @ @ @ @ @FFIdi  ).."9"9; ; 	;r   T)r#   r   )r(   r)   r*   r   r   r   r6   FactoryrR   r   r   collectionsOrderedDictr   r   classmethodrm   Tabler,   r-   r   r   r   r    r+   rK   r   r   r
   r   r      s3         4799Ddgldl400111G47<4<#5#5666L47<4<0G#H#HIIIL$'$'''K PT0 0#':07=t7L0Xc0 0 0 [0d 
 
 
 [
,;- ;# ; ; ; ; ; ;r   r   Ttgr   c                 b   i }| j                                         D ]Q\  }t                              |          }|||j        <   |j                                        D ]}|||j        <   Rt          j                    d}|rx|dk     rr|dz  }t          |
                                          D ]Ct          fd|         j        D                       r|                              <    nD|r|dk     r|rt          d          t                                                    S )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   D   K   | ]}|d          v p|d          k    V  dS )r   Nr   )r5   r   orderedr!   s     r
   r7   zschema.<locals>.<genexpr>P  s9      ``cCFg%9#a&E/``````r   z7there seem to be cyclic dependencies between the tables)	tabledictitemsr   r   r6   r   valuesr   r   rR   r?   allr   pop
ValueError)	r   r   tablestnametatir   r!   s	          @@r
   schemar   3  si    F**,, ! !u))-F * H Hqv.'')) 	! 	!B F27OO	! %''G	A  QWW	Q&++--(( 	 	E`````VE]E_````` !'E!2!2  QWW  TRSSS  !!!r   c            
       $   e Zd ZdZ	 	 	 ddedej        ej        ej	        e
f                  dej        e         dej        e         fdZdd	Zed
ej        e
ef         fd            Zedde
dej        e
         d
e
fd            Zd
ej        ej        ej        f         fdZd
efdZde
de
d
ej        e
         fdZd
ej        ej        e
         e
df         fdZd
ej        e
ej        ej                 f         fdZ d Z!ddZ"dddddZ#dS )Databasea  
    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.
    NTr   fnamer>   r   c                     |pt           j        | _        |rt          j        |          nd | _        |                     ||           d | _        d S Nr   )r   name_translatorr>   pathlibPathr   init_schema_connection)r%   r   r   r>   r   s        r
   __init__zDatabase.__init__m  sV     #>h&>,1;W\%(((t
7PQQQr   c                 \    || _         | j         rt          | j         |          ng | _        d S r   )r   r   r   )r%   r   r   s      r
   r   zDatabase.init_schemay  sD    MQW]fG/HJ J J JZ\ 	r   r#   c                 $    d | j         D             S )Nc                     i | ]
}|j         |S r   r6   )r5   r   s     r
   
<dictcomp>z"Database.tdict.<locals>.<dictcomp>  s    ///a///r   )r   rf   s    r
   tdictzDatabase.tdict~  s    //4;////r   r!   r"   c                 
    |p| S )af  
        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   zDatabase.name_translator  s     r   c                     | j         r8t          j        t          j        t          | j                                       S | j        st          j        d          | _        | j        S )Nz:memory:)r   
contextlibclosingsqlite3connectr+   r   rf   s    r
   
connectionzDatabase.connection  sV    : 	H%goc$*oo&F&FGGG 	;&z::Dr   c           
         d                               }nd}d                     t          |                     |j        |j        d         j                            t          |                     |j        |j        d         j                            t          |                     |j                            |          }|                    |          }fd|                                D             S )NzWHERE context = '{0}'r|   zgSELECT {0}, group_concat({1}, ' '), group_concat(COALESCE(context, ''), '||')
FROM {2} {3} GROUP BY {0}r   r   c           
          i | ]V}|d          fdt          |d                                         |d                             d                    D             WS )r   c                 &    g | ]\  }}||fn|S r   r   )r5   rC   vr   s      r
   rD   z;Database.select_many_to_many.<locals>.<dictcomp>.<listcomp>  s?     D D Dq! %_Aq66! D D Dr   r      z||)zipsplit)r5   rr   s     r
   r   z0Database.select_many_to_many.<locals>.<dictcomp>  s     \ \ \HI aD D D D D"1Q4::<<1D1A1ABBD D D\ \ \r   )r4   r:   r>   r6   r   rP   rS   )r%   r=   r!   r   context_sqlrK   rT   s      `   r
   select_many_to_manyzDatabase.select_many_to_many  s    188AAKKK#Vt~~ej%-2B2GHHIIt~~ej%-2B2GHHIIt~~ej1122	  	 ZZ__\ \ \ \MO[[]]\ \ \ 	\r   r   rw   c                     | j         D ]Z}|                     |          |k    r?| j         |         j        D ],}|                     ||j                  |k    r|j        c c S -[dS )ze
        :return: separator for the column specified by db schema names `tname` and `cname`.
        N)r   r>   r   r6   re   )r%   r   rw   r6   r   s        r
   re   zDatabase.separator  s     J 	- 	-D~~d##u,,:d+3 - -C~~dCH55>>"},,,,, ?	- 	-r   c                 d    |                      ||          }|r|pd                    |          n|S )Nr|   )re   r   )r%   r   rw   valueseps        r
   split_valuezDatabase.split_value  s7    nnUE**+.9""3'''E9r   c           
      :   t          j        t                    }|                                 5 }| j        j        D ]D}i i t          j        t                    c}}| j        |         }|j        D ]}|j	        t          g|                     ||j	                  <   |j        t          v r;t          |j                 d         |                     ||j	                           d<   n9t          |j                 j        |                     ||j	                           d<   |j        rM|j        dk    r$|j        ||                     ||j	                  <   d||                     ||j	                  <   |j                                        D ]S\  }}|                     |||                                          D ]$\  }	}
|
||	         |                     ||          <   %Tt)          ||                     |                    \  }}|D ]s}t          j                    }t-          ||          D ]\  }
|v rb|
d|<   |
sg |<   |         dk    rt/          j        |
          |<   =fd|
pd                    |                   D             |<   k|
          d         |
          nd|<   |j        r?t7          |j                  dk    r'||                     ||j        d                            nd}	|                    d	 |j        D                        |                    |                    |	i                      ||                     |                                       |           uF	 ddd           n# 1 swxY w Y   |S )
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   jsonNc                 >    g | ]}          d          |          S )r   r   )r5   v_ra   rC   s     r
   rD   z!Database.read.<locals>.<listcomp>  s+    ']']']b
1b(9(9']']']r   r|   r   c                     i | ]}|g S r   r   )r5   rC   s     r
   r   z!Database.read.<locals>.<dictcomp>  s    @@@a@@@r   )r   defaultdictrR   r   r   r   dictr   r   r6   r   r>   r^   r_   r   rd   re   r   r   r   rV   r   r   r   loadsr   r   r   updaterp   rq   )r%   resconnr   sepsrefsr!   r   r   pkr   rU   r@   rL   rO   ra   rC   s                  @@r
   rb   zDatabase.read  s   
 %d++__ /	9$* .9 .9
 ')"k.Ed.K.K#t
5) != K KC@C(?SGDNN5#(;;<}00FNs}F]^_F`uch ? ?@CC &cm4>  uch ? ?@C} K=H44DGMDsx!@!@AADJDsx!@!@A  %17799 A AGC!%!9!9$C!H!H!N!N!P!P A AA?@Rs!;!;<<A $D$..*?*?@@
d 9 9C#/11A #D# O O199 y'+!%& ^')!!%aF!2!2'+z!}}!']']']']']QW"OOTXYZT[D\D\']']']!78}=71:a=#3#3#3$AaDD ,W14U5F1G1G11L1L 4>>%1B11EFFGGRV HH@@U-?@@@AAAHHTXXb"--...u--.55a8888%99.9/	9 /	9 /	9 /	9 /	9 /	9 /	9 /	9 /	9 /	9 /	9 /	9 /	9 /	9 /	9` 
s   MNNNc                 
    ||fS )a  
        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_contextz"Database.association_table_context  s     V|r   Fc                 R     | j         d|||d| j                                        S )Nforce
_exists_ok_skip_extrar   )writer   rb   )r%   _forcer  r  s       r
   write_from_tgzDatabase.write_from_tg  s?    tz !#  gllnn	  	r   r
  c          
         | j         rC| j                                         r*|st          d          | j                                          |                                 5 }| j        D ]0}|                    |                    | j                             1|                    d           |	                                 t          j        t                    }| j        D ]0}|j        |vrg g }
}	d |j        D             }t          ||j                           D ]\  }}|j        r+t#          |j                  dk    r||j        d                  nd}g }|                                D ]d\  }}||j        v rx|sJ |j        |         }t)          |j        gd |j        D             z             }|pg D ]:}|                     |||          \  }}||                             |||f           ;||vr%|rt          d	                    |                    ||         t1          |t                    rIj        d
k    r)j        pd                    fd|D                       }n.t9          j        |          }n|                    |          nd}|dk    r|
                    j                   |                    |           f|	                    t)          |                     t?          || j        |j        |
g|	R   2|                                D ](\  }}	t?          || j        |d         |dd         g|	R   )|	                                 ddd           dS # 1 swxY w Y   dS )z
        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)r>   zPRAGMA foreign_keys = ON;c                     i | ]
}|j         |S r   r   r   s     r
   r   z"Database.write.<locals>.<dictcomp>  s    555a555r   r   r   Nc                     g | ]	}|j         
S r   r   r   s     r
   rD   z"Database.write.<locals>.<listcomp>%  s    6R6R6R!qv6R6R6Rr   z$unspecified column {0} found in datar   ;c              3   F   K   | ]}                     |          pd V  dS )r|   N)ra   )r5   vvr   s     r
   r7   z!Database.write.<locals>.<genexpr>6  sS       DK DKBDB(=2DK DK DK DK DK DKr   ) r   existsr   unlinkr   r   rP   rK   r>   commitr   r   rR   r6   r   	enumerater   r   r   r   tupler  rq   r4   
isinstancer^   re   r8   r   dumpsra   rI   )r%   r  r  r  r   r=   r!   r  r   r@   r?   rU   r   rL   r  r   rC   r   r   atkeyr  r  r   r   s                          @r
   r  zDatabase.write  s6    : 	$$*++-- 	$ $ !VWWW
!!###__ 5	" @ @

599t~9>>????JJ2333IIKKK*400D[ (@ (@6&&d5519555'af66 "/ "/FAs=O-0-?-?1-D-D Q]1-..JN F #		 - -1..#%II2!"!2B$)27)6R6Rrz6R6R6R*R$S$SE ()wB H H040N0NqRSUW0X0Xg $U 2 2Bg3F G G G GH  !}}#. !Z$,*4(N(U(UVW(X(X+Z +Z %Z"&q'C)!T22 N#&=H#<#<),)=#(C(C DK DK DK DKHIDK DK DK )K )KAA )-
1AA67mCKKNNN Avv $CH 5 5 5"MM!,,,,KKf....r4>164?$?????#zz|| G Gtr4>58U122YFFFFFFIIKKKk5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	 5	s    LM22M69M6)NNTr   r   )FFF)$r(   r)   r*   r   r   r,   r-   Unionr   r   r+   r    r   r   r   propertyDictr   r   staticmethodr   r   
Connectionr   r   r   r   r   re   Listr   r   rb   r  r  r  r   r   r
   r   r   Z  sF        * GK;??C
  
 
  ?6<c0A#BC
  '78	
 
 (.t'<
  
  
  
 ] ] ] ]
 0v{3	>2 0 0 0 X0 
 
s 
FOC,@ 
C 
 
 
 \
 FL);Z=O)OP        \ \ \ \ \"-s -3 -6?33G - - - -:&,v{3?OQTVZ?Z2[ : : : :6fk#v{63E'F"FG 6 6 6 6p       #u% A A A A A A Ar   r   r   )%r   r   r,   r   r   r   r   r   r   r   rm   csvw.datatypesr   csvw.metadatar   r   r_   Protocolr    r/   r:   r#  r+   SequencerR   r-   r   rI   Tupler$  rV   r	   rX   objectr   r   r   r   r   r
   <module>r+     s)   6                    $ $ $ $ $ $ $ $ $ $ $ $   	
 	
 	,,--/
 	..88:
 	# 0    v   
    v   
< < < ,1  w! & % 	
 ?4(   D%w! %# %&,v{3?OQWQ`?`2a % % % % @= @= @= @= @= @= @= @=F m; m; m; m; m; m; m; m;b ?C$" $"t $"&,od&;$"GM{S\G]$" $" $" $"Nk k k k kv k k k k kr   