]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
adjusted docs to account for import convention, proper sqlite calling convention
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Nov 2005 06:00:41 +0000 (06:00 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 30 Nov 2005 06:00:41 +0000 (06:00 +0000)
doc/build/content/adv_datamapping.myt
doc/build/content/datamapping.myt
doc/build/content/dbengine.myt
doc/build/content/metadata.myt
doc/build/content/sqlconstruction.myt

index 98aad5e767c1d108779b3bff3d9e16f7c5ba4787..54f4dbaaf24adead1d574b856665a2379c2a6d31 100644 (file)
@@ -5,9 +5,8 @@
 
 <p>To start, heres the tables we will work with again:</p>
        <&|formatting.myt:code&>
-        from sqlalchemy.schema import *
-        import sqlalchemy.engine as engine
-        db = engine.create_engine('sqlite', 'mydb', {}, echo=True)
+        from sqlalchemy import *
+        db = create_engine('sqlite', {'filename':'mydb'}, echo=True)
         
         # a table to store users
         users = Table('users', db,
index 9c8f631dcd2b8fb5c16511c7e6e89ad3873c3589..5c4c3e4e06b439cf871e2ec0ff09e2157444e185 100644 (file)
@@ -14,8 +14,7 @@ The Mapper's role is to perform SQL operations upon the database, associating in
 </p>
 <&|doclib.myt:item, name="example", description="Basic Example" &>
         <&|formatting.myt:code&>
-        from sqlalchemy.schema import *
-        from sqlalchemy.mapper import *
+        from sqlalchemy import *
         
         # table metadata
         users = Table('users', engine, 
@@ -138,10 +137,8 @@ INSERT INTO users (user_name, password) VALUES (:user_name, :password)
 <&|doclib.myt:item, name="relations", description="Defining and Using Relationships" &>
 <p>So that covers how to map the columns in a table to an object, how to load objects, create new ones, and save changes.  The next step is how to define an object's relationships to other database-persisted objects.  This is done via the <span class="codeline">relation</span> function provided by the mapper module.  So with our User class, lets also define the User has having one or more mailing addresses.  First, the table metadata:</p>
         <&|formatting.myt:code&>
-        from sqlalchemy.schema import *
-        from sqlalchemy.mapper import *
-        import sqlalchemy.databases.sqlite as sqlite
-        engine = sqlite.engine('mydb', {})
+        from sqlalchemy import *
+        engine = create_engine('sqlite', {'filename':'mydb'})
         
         # define user table
         users = Table('users', engine, 
index d9385c05ed430e8a196d6662e3d76988b05a1c6d..754b4f71f983894049a85c2c378ab8b51edab248 100644 (file)
     <p>An example of connecting to each engine is as follows:</p>
     
     <&|formatting.myt:code&>
-    import sqlalchemy.engine as engine
+    from sqlalchemy.engine import *
 
     # sqlite in memory    
-    sqlite_engine = engine.create_engine('sqlite', {'filename':':memory:'}, **opts)
+    sqlite_engine = create_engine('sqlite', {'filename':':memory:'}, **opts)
     
     # sqlite using a file
-    sqlite_engine = engine.create_engine('sqlite', {'filename':'querytest.db'}, **opts)
+    sqlite_engine = create_engine('sqlite', {'filename':'querytest.db'}, **opts)
 
     # postgres
-    postgres_engine = engine.create_engine('postgres', 
+    postgres_engine = create_engine('postgres', 
                             {'database':'test', 
                             'host':'127.0.0.1', 
                             'user':'scott', 
                             'password':'tiger'}, **opts)
 
     # oracle
-    oracle_engine = engine.create_engine('oracle', 
+    oracle_engine = create_engine('oracle', 
                             {'dsn':'mydsn', 
                             'user':'scott', 
                             'password':'tiger'}, **opts)
     </&>
     <p>Note that the general form of connecting to an engine is:</p>
     <&|formatting.myt:code&>
-           engine = sqlalchemy.engine.create_engine(
+           engine = create_engine(
                         <enginename>, 
                         {<named DBAPI arguments>}, 
                         <sqlalchemy options>
                     )
     </&>
     <p>The second argument is a dictionary whose key/value pairs will be passed to the underlying DBAPI connect() method as keyword arguments.  Any keyword argument supported by the DBAPI module can be in this dictionary.</p>
+    <p>An additional URL-string based calling style will also be added soon, as this is a highly requested feature.
+    </p>
     </&>
     <&|doclib.myt:item, name="options", description="Database Engine Options" &>
     <p>The remaining arguments to <span class="codeline">create_engine</span> are keyword arguments that are passed to the specific subclass of <span class="codeline">sqlalchemy.engine.SQLEngine</span> being used,  as well as the underlying <span class="codeline">sqlalchemy.pool.Pool</span> instance.  All of the options described in the previous section <&formatting.myt:link, path="pooling_configuration"&> can be specified, as well as engine-specific options:</p>
index 49ca04bb277bf1703a523892f95146edab42f34e..b0d66a498681604b5efa14c1a4bac53f4f8ab1c3 100644 (file)
@@ -5,8 +5,7 @@
     <p>The core of SQLAlchemy's query and object mapping operations is table metadata, which are Python objects that describe tables.  Metadata objects can be created by explicitly naming the table and all its properties, using the Table, Column, ForeignKey, and Sequence objects imported from <span class="codeline">sqlalchemy.schema</span>, and a database engine constructed as described in the previous section, or they can be automatically pulled from an existing database schema.  First, the explicit version: </p>
         <&|formatting.myt:code&>
         from sqlalchemy.schema import *
-        import sqlalchemy.engine as engine
-        engine = engine.create_engine('sqlite', ':memory:', {}, **opts)
+        engine = create_engine('sqlite', {'filename':':memory:'}, **opts)
         
         users = Table('users', engine, 
             Column('user_id', Integer, primary_key = True),
@@ -139,8 +138,8 @@ DROP TABLE employees
     
         <&|formatting.myt:code&>
         # create two engines
-        sqlite_engine = engine.create_engine('sqlite', 'querytest.db', {})
-        postgres_engine = engine.create_engine('postgres', 
+        sqlite_engine = create_engine('sqlite', {'filename':'querytest.db'})
+        postgres_engine = create_engine('postgres', 
                             {'database':'test', 
                             'host':'127.0.0.1', 'user':'scott', 'password':'tiger'})
         
@@ -161,7 +160,7 @@ DROP TABLE employees
             Column('user_name', String(50))
         )
 
-        sqlite_engine = engine.create_engine('sqlite', 'querytest.db', {})
+        sqlite_engine = create_engine('sqlite', {'filename':'querytest.db'})
         sqlite_users = users.toengine(sqlite_engine)
         sqlite_users.create()
         </&>        
index ec81e44c5fc1a17fd2e0b3b50eb7567257a5f1d4..65dc8f0134a60732f4b68791810022e1cf482dd6 100644 (file)
@@ -11,9 +11,8 @@
     
     <p>For this section, we will assume the following tables:
        <&|formatting.myt:code&>
-        from sqlalchemy.schema import *
-        import sqlalchemy.engine as engine
-        db = engine.create_engine('sqlite', 'mydb', {}, echo=True)
+        from sqlalchemy import *
+        db = create_engine('sqlite', {'filename':'mydb'}, echo=True)
         
         # a table to store users
         users = Table('users', db,
@@ -50,7 +49,7 @@
     <&|doclib.myt:item, name="select", description="Simple Select" &>
         <p>A select is done by constructing a <span class="codeline">Select</span> object with the proper arguments, adding any extra arguments if desired, then calling its <span class="codeline">execute()</span> method.
         <&|formatting.myt:code&>
-            from sqlalchemy.sql import *
+            from sqlalchemy import *
             
             # use the select() function defined in the sql package
             s = select([users])