index.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <!doctype html>
  2. <html lang="en-nz">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Invercargill-Sql-Inversion — Astrologue Developer</title>
  7. <meta name="description" content="The Inversion integrations for Invercargill-Sql: DatabaseConfigurator, MigrationStartupService and InversionTypeProvider wire the database into the dependency-injection container. Free software, LGPL-3.0-or-later.">
  8. <meta name="color-scheme" content="light dark">
  9. <meta name="theme-color" content="#f2ebda" media="(prefers-color-scheme: light)">
  10. <meta name="theme-color" content="#0a0a12" media="(prefers-color-scheme: dark)">
  11. <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Ccircle cx='32' cy='32' r='27' fill='none' stroke='%23a8801f' stroke-width='4'/%3E%3Cpath d='M32 8l6 18 18 6-18 6-6 18-6-18-18-6 18-6z' fill='%23a8801f'/%3E%3Ccircle cx='32' cy='32' r='4' fill='%23003078'/%3E%3C/svg%3E">
  12. <meta property="og:title" content="Invercargill-Sql-Inversion — Astrologue Developer">
  13. <meta property="og:description" content="DatabaseConfigurator, MigrationStartupService and InversionTypeProvider: the glue that wires Invercargill-Sql into the Inversion container.">
  14. <meta property="og:type" content="website">
  15. <link rel="stylesheet" href="../../assets/css/style.css">
  16. </head>
  17. <body>
  18. <a class="skip-link" href="#main">Skip to content</a>
  19. <header class="masthead">
  20. <div class="container masthead__inner">
  21. <a class="brand" href="../../">
  22. <img class="brand__logo brand__logo--light" src="../../assets/img/astrologue-light.png" width="392" height="89" alt="Astrologue">
  23. <img class="brand__logo brand__logo--dark" src="../../assets/img/astrologue-dark.png" width="392" height="89" alt="Astrologue">
  24. </a>
  25. <nav class="site-nav" aria-label="Primary">
  26. <ul class="site-nav__list">
  27. <li><a href="../../">Home</a></li>
  28. <li><a href="../../#news">News</a></li>
  29. <li><a href="../../#download">Download</a></li>
  30. <li><a href="../" aria-current="page">Developer</a></li>
  31. <li><a class="nav-cta" href="../../#download">Get Astrologue</a></li>
  32. </ul>
  33. </nav>
  34. </div>
  35. </header>
  36. <main id="main">
  37. <nav class="breadcrumb" aria-label="Breadcrumb">
  38. <div class="container">
  39. <ol>
  40. <li><a href="../../">Astrologue</a></li>
  41. <li><a href="../">Developer</a></li>
  42. <li aria-current="page">Invercargill-Sql-Inversion</li>
  43. </ol>
  44. </div>
  45. </nav>
  46. <section class="docs-header">
  47. <div class="container">
  48. <p class="kicker"><span>Data · The database, wired</span></p>
  49. <h1>Invercargill-Sql-Inversion</h1>
  50. <p class="lede">The Inversion integrations for Invercargill-Sql. Three classes — DatabaseConfigurator, MigrationStartupService and InversionTypeProvider — turn the database layer from something you wire by hand into something the container hands you.</p>
  51. <dl class="docs-facts">
  52. <div><dt>Version</dt> <dd><code>0.1</code></dd></div>
  53. <div><dt>Licence</dt> <dd>LGPL-3.0-or-later</dd></div>
  54. <div><dt>Package</dt> <dd><code>usm&nbsp;install&nbsp;invercargill-sql-inversion</code></dd></div>
  55. <div><dt>Language</dt> <dd>Vala</dd></div>
  56. </dl>
  57. </div>
  58. </section>
  59. <section class="band band--plain" id="docs">
  60. <div class="container docs-layout">
  61. <nav class="docs-toc" aria-label="On this page">
  62. <h2>On this page</h2>
  63. <ul>
  64. <li><a href="#overview">Overview</a></li>
  65. <li><a href="#features">Features</a></li>
  66. <li><a href="#installation">Installation</a></li>
  67. <li><a href="#usage">Usage &amp; documentation</a></li>
  68. <li><a href="#package">Package &amp; source</a></li>
  69. </ul>
  70. </nav>
  71. <div class="docs-prose">
  72. <header class="section-head" id="overview">
  73. <p class="kicker"><span>Overview</span></p>
  74. <h2>Integration glue, honestly scoped</h2>
  75. </header>
  76. <p>This repository ships no README — its three source files are the whole story, and this page summarises what they actually do. Invercargill-Sql-Inversion is glue in the good sense: the connective tissue that lets an application declare its database, entities, projections and migrations once, and have the <a href="../inversion/">Inversion</a> container resolve <a href="../invercargill-sql/">Invercargill-Sql</a>'s connections, dialects, runners, mappers and sessions ever after.</p>
  77. <p>Without it, every application repeats the same wiring — open a connection from a connection string, create a dialect, build a migration runner, register a type registry, construct sessions. With it, that wiring is one configurator object and a handful of registrations.</p>
  78. <header class="section-head" id="features">
  79. <p class="kicker"><span>Features</span></p>
  80. <h2>The three classes</h2>
  81. </header>
  82. <ul class="docs-features">
  83. <li><strong>DatabaseConfigurator.</strong> Registers a connection from a connection string, plus the dialect factory, migration runner, type provider and ORM session — with an auto-detected lifecycle.</li>
  84. <li><strong>add_entity, add_migration, add_projection.</strong> Fluent registration of mappers, migrations and projection definitions, each tagged with typed metadata.</li>
  85. <li><strong>MigrationStartupService.</strong> A startup-lifecycle service that gathers every registered migration and runs the schema to latest when the container initialises.</li>
  86. <li><strong>InversionTypeProvider.</strong> Answers "which mapper or projection belongs to this Vala type?" by querying registration metadata — the bridge the ORM's registry needs.</li>
  87. <li><strong>Lifecycle detection.</strong> In-memory databases register as singletons, file databases as scoped — the sensible default, overridable per registration.</li>
  88. </ul>
  89. <header class="section-head" id="installation">
  90. <p class="kicker"><span>Installation</span></p>
  91. <h2>Getting the library</h2>
  92. </header>
  93. <figure class="code-plate">
  94. <pre><code>usm install invercargill
  95. usm install invercargill-sql
  96. usm install inversion
  97. usm install invercargill-sql-inversion</code></pre>
  98. <figcaption>USM resolves the dependency chain; the explicit steps are for reading order.</figcaption>
  99. </figure>
  100. <p>From source:</p>
  101. <figure class="code-plate">
  102. <pre><code>git clone &lt;the Invercargill-Sql-Inversion repository&gt;
  103. cd Invercargill-Sql-Inversion
  104. meson setup build
  105. ninja -C build
  106. ninja -C build install</code></pre>
  107. <figcaption>Requires the three libraries above installed first.</figcaption>
  108. </figure>
  109. <figure class="code-plate">
  110. <pre><code>valac --pkg invercargill-sql-inversion my-program.vala</code></pre>
  111. <figcaption>The binding pulls in its <code>.deps</code> chain automatically.</figcaption>
  112. </figure>
  113. <header class="section-head" id="usage">
  114. <p class="kicker"><span>Usage &amp; documentation</span></p>
  115. <h2>Wiring a database in one place</h2>
  116. </header>
  117. <p>The configurator injects the container it lives in, so configuration reads as plain registrations:</p>
  118. <figure class="code-plate">
  119. <pre><code>var db = new DatabaseConfigurator();
  120. db.register_connection("sqlite::memory:");</code></pre>
  121. <figcaption>The entry point, from <code>src/DatabaseConfigurator.vala</code>. In-memory databases default to the singleton lifecycle; file databases to scoped — pass a lifecycle to override.</figcaption>
  122. </figure>
  123. <p>That one call registers the connection itself, a transient <code>SqlDialect</code> from the connection string's scheme, a transient <code>MigrationRunner</code>, the <code>TypeProvider</code>, and an <code>OrmSession</code> sharing the connection's lifecycle. Then entities, projections and migrations join the container with their own fluent calls:</p>
  124. <figure class="code-plate">
  125. <pre><code>db.add_entity&lt;User&gt;(b =&gt; b
  126. .table("users")
  127. .column&lt;int64?&gt;("id", u =&gt; u.id, (u, v) =&gt; u.id = v)
  128. .column&lt;string&gt;("name", u =&gt; u.name, (u, v) =&gt; u.name = v));
  129. db.add_projection&lt;UserSummary&gt;(b =&gt; { /* projection columns */ });
  130. db.add_migration&lt;V001_CreateUsers&gt;();</code></pre>
  131. <figcaption>Shape from <code>src/DatabaseConfigurator.vala</code> — each registration tags the container entry with typed <code>MapperTypeInfo</code> metadata.</figcaption>
  132. </figure>
  133. <p>To have the schema ready before the application serves anything, one more line:</p>
  134. <figure class="code-plate">
  135. <pre><code>db.migrate_on_startup();
  136. container.initialise();</code></pre>
  137. <figcaption><code>migrate_on_startup()</code> registers the <code>MigrationStartupService</code> on the STARTUP lifecycle; when the container initialises, it creates a scope, resolves every registered <code>Migration</code>, hands them to the runner, and migrates to latest.</figcaption>
  138. </figure>
  139. <p>Downstream, the ORM asks for mappers through the type provider rather than a hand-built registry:</p>
  140. <figure class="code-plate">
  141. <pre><code>public class InversionTypeProvider : Object, TypeProvider {
  142. private Scope scope = inject&lt;Scope&gt;();
  143. public EntityMapper? get_mapper_for_type(GLib.Type type) throws Error {
  144. var reg = scope.get_registrations(typeof(EntityMapper))
  145. .where(r =&gt; r.get_metadata&lt;MapperTypeInfo&gt;()
  146. .any(i =&gt; i.mapper_type == type))
  147. .first_or_default();
  148. return reg == null ? null
  149. : (EntityMapper)scope.resolve_registration(reg);
  150. }
  151. // get_projection_for_type, has_mapper_for_type likewise
  152. }</code></pre>
  153. <figcaption>Condensed from <code>src/InversionTypeProvider.vala</code> — the metadata written at registration time is what answers the type question here.</figcaption>
  154. </figure>
  155. <header class="section-head" id="package">
  156. <p class="kicker"><span>Package &amp; source</span></p>
  157. <h2>The ledger</h2>
  158. </header>
  159. <dl class="docs-package">
  160. <div><dt>Version</dt><dd><code>0.1</code> (from <code>MANIFEST.usm</code>)</dd></div>
  161. <div><dt>Licence</dt><dd>LGPL-3.0-or-later — free to run, study, share and improve; the LGPL keeps it free to link from any program.</dd></div>
  162. <div><dt>Package</dt><dd><code>usm install invercargill-sql-inversion</code></dd></div>
  163. <div><dt>Provides</dt><dd><code>libinvercargill-sql-inversion.so</code>, <code>invercargill-sql-inversion.h</code>, <code>invercargill-sql-inversion.vapi</code> + <code>.deps</code>, <code>invercargill_sql_inversion-0.1.gir</code>, <code>invercargill_sql_inversion-0.1.typelib</code>, <code>invercargill-sql-inversion.pc</code></dd></div>
  164. <div><dt>Needs at runtime</dt><dd>GLib, GObject, <code>libinvercargill-1.so</code>, <code>libinvercargill-sql.so</code> and <code>libinversion-0.1.so</code>.</dd></div>
  165. <div><dt>Source</dt><dd>The repository <code>Tilo15/Invercargill-Sql-Inversion</code> on the Astrologue forge (git over ssh, port 222). Free software: the licence guarantees your right to the source.</dd></div>
  166. </dl>
  167. <nav class="docs-siblings" aria-label="Neighbours in the catalogue">
  168. <p>Its neighbours:</p>
  169. <ul>
  170. <li><a href="../invercargill-sql/">Invercargill-Sql</a></li>
  171. <li><a href="../inversion/">Inversion</a></li>
  172. <li><a href="../spry/">Spry</a></li>
  173. </ul>
  174. </nav>
  175. <nav class="docs-pager" aria-label="Project pages">
  176. <a class="docs-pager__link docs-pager__link--prev" href="../invercargill-sql/">
  177. <span>Previous</span>
  178. <strong>Invercargill-Sql</strong>
  179. </a>
  180. <p class="docs-pager__up"><a href="../">All eleven</a></p>
  181. <a class="docs-pager__link docs-pager__link--next" href="../astralis/">
  182. <span>Next in the catalogue</span>
  183. <strong>Astralis</strong>
  184. </a>
  185. </nav>
  186. </div>
  187. </div>
  188. </section>
  189. </main>
  190. <footer class="site-footer">
  191. <div class="container">
  192. <div class="footer-grid">
  193. <div class="foot-brand">
  194. <img class="brand__logo brand__logo--dark" src="../../assets/img/astrologue-dark.png" width="392" height="89" alt="Astrologue">
  195. <p>An operating system for change — kept for self sufficiency, resilience, and software freedom, so regular people can hold the power of general purpose computers in their own hands.</p>
  196. </div>
  197. <nav aria-label="The four freedoms">
  198. <p class="foot-title">The Four Freedoms</p>
  199. <ol class="freedoms">
  200. <li><strong>Run</strong> the software as you wish, for any purpose.</li>
  201. <li><strong>Study</strong> the source and change it to do your computing as you wish.</li>
  202. <li><strong>Share</strong> copies so you can help others.</li>
  203. <li><strong>Modify</strong> and publish your versions so everyone benefits.</li>
  204. </ol>
  205. </nav>
  206. <nav aria-label="Site">
  207. <p class="foot-title">Site</p>
  208. <ul class="foot-list">
  209. <li><a href="../../">Home</a></li>
  210. <li><a href="../../#news">News</a></li>
  211. <li><a href="../../#download">Download</a></li>
  212. <li><a href="../">Developer</a></li>
  213. </ul>
  214. </nav>
  215. </div>
  216. <p class="colophon">Set in Cinzel and EB Garamond (SIL Open Font License). Astrologue is free software, licensed GPL-3.0-or-later: take it, tend it, pass it on. The libraries are LGPL-3.0-or-later, so they remain free to link.</p>
  217. </div>
  218. </footer>
  219. </body>
  220. </html>