File tree Expand file tree Collapse file tree 9 files changed +517
-0
lines changed Expand file tree Collapse file tree 9 files changed +517
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/bin/env python
2
+
3
+ import click
4
+ from ellar .app import AppFactory , current_injector
5
+ from ellar .utils .importer import get_main_directory_by_stack
6
+ from ellar_cli .main import create_ellar_cli
7
+ from models import User
8
+
9
+ from ellar_sql import EllarSQLModule , MigrationOption , model
10
+
11
+
12
+ def bootstrap ():
13
+ path = get_main_directory_by_stack (
14
+ "__main__/__parent__/__parent__/dumbs/custom_directory" , stack_level = 1
15
+ )
16
+ application = AppFactory .create_app (
17
+ modules = [
18
+ EllarSQLModule .setup (
19
+ databases = "sqlite:///app.db" ,
20
+ migration_options = MigrationOption (
21
+ directory = "temp_migrations" ,
22
+ context_configure = {"compare_types" : True },
23
+ ),
24
+ root_path = str (path ),
25
+ )
26
+ ]
27
+ )
28
+ return application
29
+
30
+
31
+ cli = create_ellar_cli ("custom_directory:bootstrap" )
32
+
33
+
34
+ @cli .command ()
35
+ def add_user ():
36
+ session = current_injector .get (model .Session )
37
+ user = User (name = "Custom Directory App Ellar" )
38
+ session .add (user )
39
+
40
+ session .commit ()
41
+
42
+ click .echo (f"<User name={ user .name } id={ user .id } >" )
43
+
44
+
45
+ if __name__ == "__main__" :
46
+ cli ()
Original file line number Diff line number Diff line change
1
+ #!/bin/env python
2
+ import click
3
+ from ellar .app import AppFactory , current_injector
4
+ from ellar .utils .importer import get_main_directory_by_stack
5
+ from ellar_cli .main import create_ellar_cli
6
+ from models import User
7
+
8
+ from ellar_sql import EllarSQLModule , model
9
+
10
+
11
+ def bootstrap ():
12
+ path = get_main_directory_by_stack (
13
+ "__main__/__parent__/__parent__/dumbs/default" , stack_level = 1
14
+ )
15
+ application = AppFactory .create_app (
16
+ modules = [
17
+ EllarSQLModule .setup (
18
+ databases = "sqlite:///app.db" ,
19
+ migration_options = {"context_configure" : {"compare_types" : False }},
20
+ root_path = str (path ),
21
+ )
22
+ ]
23
+ )
24
+ return application
25
+
26
+
27
+ cli = create_ellar_cli ("default:bootstrap" )
28
+
29
+
30
+ @cli .command ()
31
+ def add_user ():
32
+ session = current_injector .get (model .Session )
33
+ user = User (name = "default App Ellar" )
34
+ session .add (user )
35
+
36
+ session .commit ()
37
+ click .echo (f"<User name={ user .name } id={ user .id } >" )
38
+
39
+
40
+ if __name__ == "__main__" :
41
+ cli ()
Original file line number Diff line number Diff line change
1
+ #!/bin/env python
2
+ import ellar_cli .click as click
3
+ from ellar .app import AppFactory , current_injector
4
+ from ellar .utils .importer import get_main_directory_by_stack
5
+ from ellar_cli .main import create_ellar_cli
6
+ from models import User
7
+ from sqlalchemy .ext .asyncio import AsyncSession
8
+
9
+ from ellar_sql import EllarSQLModule
10
+
11
+
12
+ def bootstrap ():
13
+ path = get_main_directory_by_stack (
14
+ "__main__/__parent__/__parent__/dumbs/default_async" , stack_level = 1
15
+ )
16
+ application = AppFactory .create_app (
17
+ modules = [
18
+ EllarSQLModule .setup (
19
+ databases = "sqlite+aiosqlite:///app.db" ,
20
+ migration_options = {"context_configure" : {"compare_types" : False }},
21
+ root_path = str (path ),
22
+ )
23
+ ]
24
+ )
25
+ return application
26
+
27
+
28
+ cli = create_ellar_cli ("default_async:bootstrap" )
29
+
30
+
31
+ @cli .command ()
32
+ @click .run_as_async
33
+ async def add_user ():
34
+ session = current_injector .get (AsyncSession )
35
+ user = User (name = "default App Ellar" )
36
+ session .add (user )
37
+
38
+ await session .commit ()
39
+ await session .refresh (user )
40
+ await session .close ()
41
+
42
+ click .echo (f"<User name={ user .name } id={ user .id } >" )
43
+
44
+
45
+ if __name__ == "__main__" :
46
+ cli ()
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ from ellar_sql import model
4
+
5
+
6
+ class Base (model .Model ):
7
+ __base_config__ = {"as_base" : True }
8
+
9
+
10
+ class User (Base ):
11
+ id = model .Column (model .Integer , primary_key = True )
12
+
13
+ if os .environ .get ("model_change_name" ):
14
+ name = model .Column (model .String (128 ))
15
+ else :
16
+ name = model .Column (model .String (256 ))
17
+
18
+
19
+ if os .environ .get ("multiple_db" ):
20
+
21
+ class Group (Base ):
22
+ __database__ = "db1"
23
+ id = model .Column (model .Integer , primary_key = True )
24
+ name = model .Column (model .String (128 ))
Original file line number Diff line number Diff line change
1
+ #!/bin/env python
2
+ import click
3
+ from ellar .app import AppFactory , current_injector
4
+ from ellar .utils .importer import get_main_directory_by_stack
5
+ from ellar_cli .main import create_ellar_cli
6
+ from models import Group , User
7
+
8
+ from ellar_sql import EllarSQLModule , model
9
+
10
+
11
+ def bootstrap ():
12
+ path = get_main_directory_by_stack (
13
+ "__main__/__parent__/__parent__/dumbs/multiple" , stack_level = 1
14
+ )
15
+ application = AppFactory .create_app (
16
+ modules = [
17
+ EllarSQLModule .setup (
18
+ databases = {
19
+ "default" : "sqlite:///app.db" ,
20
+ "db1" : "sqlite:///app2.db" ,
21
+ },
22
+ migration_options = {"context_configure" : {"compare_types" : False }},
23
+ root_path = str (path ),
24
+ )
25
+ ]
26
+ )
27
+ return application
28
+
29
+
30
+ cli = create_ellar_cli ("multiple_database:bootstrap" )
31
+
32
+
33
+ @cli .command ()
34
+ def add_user ():
35
+ session = current_injector .get (model .Session )
36
+ user = User (name = "Multiple Database App Ellar" )
37
+ group = Group (name = "group" )
38
+ session .add (user )
39
+ session .add (group )
40
+
41
+ session .commit ()
42
+
43
+ click .echo (
44
+ f"<User name={ user .name } id={ user .id } and Group name={ group .name } id={ group .id } >"
45
+ )
46
+
47
+
48
+ if __name__ == "__main__" :
49
+ cli ()
Original file line number Diff line number Diff line change
1
+ #!/bin/env python
2
+ import ellar_cli .click as click
3
+ from ellar .app import AppFactory , current_injector
4
+ from ellar .utils .importer import get_main_directory_by_stack
5
+ from ellar_cli .main import create_ellar_cli
6
+ from models import Group , User
7
+ from sqlalchemy .ext .asyncio import AsyncSession
8
+
9
+ from ellar_sql import EllarSQLModule
10
+
11
+
12
+ def bootstrap ():
13
+ path = get_main_directory_by_stack (
14
+ "__main__/__parent__/__parent__/dumbs/multiple_async" , stack_level = 1
15
+ )
16
+ application = AppFactory .create_app (
17
+ modules = [
18
+ EllarSQLModule .setup (
19
+ databases = {
20
+ "default" : "sqlite+aiosqlite:///app.db" ,
21
+ "db1" : "sqlite+aiosqlite:///app2.db" ,
22
+ },
23
+ migration_options = {"context_configure" : {"compare_types" : False }},
24
+ root_path = str (path ),
25
+ )
26
+ ]
27
+ )
28
+ return application
29
+
30
+
31
+ cli = create_ellar_cli ("multiple_database_async:bootstrap" )
32
+
33
+
34
+ @cli .command ()
35
+ @click .run_as_async
36
+ async def add_user ():
37
+ session = current_injector .get (AsyncSession )
38
+ user = User (name = "Multiple Database App Ellar" )
39
+ group = Group (name = "group" )
40
+
41
+ session .add (user )
42
+ session .add (group )
43
+
44
+ await session .commit ()
45
+
46
+ await session .refresh (user )
47
+ await session .refresh (group )
48
+
49
+ await session .close ()
50
+
51
+ click .echo (
52
+ f"<User name={ user .name } id={ user .id } and Group name={ group .name } id={ group .id } >"
53
+ )
54
+
55
+
56
+ if __name__ == "__main__" :
57
+ cli ()
You can’t perform that action at this time.
0 commit comments