@tauri-apps/plugin-sql 2.0.0-alpha.4 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
19
19
  ```toml
20
20
  [dependencies.tauri-plugin-sql]
21
21
  features = ["sqlite"] # or "postgres", or "mysql"
22
- version = "2.0.0-alpha"
22
+ version = "2.0.0-beta"
23
23
  # alternatively with Git
24
24
  git = "https://github.com/tauri-apps/plugins-workspace"
25
25
  branch = "v2"
@@ -105,6 +105,67 @@ const result = await db.execute(
105
105
  );
106
106
  ```
107
107
 
108
+ ## Migrations
109
+
110
+ This plugin supports database migrations, allowing you to manage database schema evolution over time.
111
+
112
+ ### Defining Migrations
113
+
114
+ Migrations are defined in Rust using the `Migration` struct. Each migration should include a unique version number, a description, the SQL to be executed, and the type of migration (Up or Down).
115
+
116
+ Example of a migration:
117
+
118
+ ```rust
119
+ use tauri_plugin_sql::{Migration, MigrationKind};
120
+
121
+ let migration = Migration {
122
+ version: 1,
123
+ description: "create_initial_tables",
124
+ sql: "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);",
125
+ kind: MigrationKind::Up,
126
+ };
127
+ ```
128
+
129
+ ### Adding Migrations to the Plugin Builder
130
+
131
+ Migrations are registered with the `Builder` struct provided by the plugin. Use the `add_migrations` method to add your migrations to the plugin for a specific database connection.
132
+
133
+ Example of adding migrations:
134
+
135
+ ```rust
136
+ use tauri_plugin_sql::{Builder, Migration, MigrationKind};
137
+
138
+ fn main() {
139
+ let migrations = vec![
140
+ // Define your migrations here
141
+ Migration {
142
+ version: 1,
143
+ description: "create_initial_tables",
144
+ sql: "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);",
145
+ kind: MigrationKind::Up,
146
+ }
147
+ ];
148
+
149
+ tauri::Builder::default()
150
+ .plugin(
151
+ tauri_plugin_sql::Builder::default()
152
+ .add_migrations("sqlite:mydatabase.db", migrations)
153
+ .build(),
154
+ )
155
+ ...
156
+ }
157
+ ```
158
+
159
+ ### Applying Migrations
160
+
161
+ Migrations are applied automatically when the plugin is initialized. The plugin runs these migrations against the database specified by the connection string. Ensure that the migrations are defined in the correct order and are idempotent (safe to run multiple times).
162
+
163
+ ### Migration Management
164
+
165
+ - **Version Control**: Each migration must have a unique version number. This is crucial for ensuring the migrations are applied in the correct order.
166
+ - **Idempotency**: Write migrations in a way that they can be safely re-run without causing errors or unintended consequences.
167
+ - **Testing**: Thoroughly test migrations to ensure they work as expected and do not compromise the integrity of your database.
168
+
108
169
  ## Contributing
109
170
 
110
171
  PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
package/dist-js/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var primitives = require('@tauri-apps/api/primitives');
3
+ var core = require('@tauri-apps/api/core');
4
4
 
5
5
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
6
6
  // SPDX-License-Identifier: Apache-2.0
@@ -31,7 +31,7 @@ class Database {
31
31
  * ```
32
32
  */
33
33
  static async load(path) {
34
- const _path = await primitives.invoke("plugin:sql|load", {
34
+ const _path = await core.invoke("plugin:sql|load", {
35
35
  db: path,
36
36
  });
37
37
  return new Database(_path);
@@ -88,7 +88,7 @@ class Database {
88
88
  * ```
89
89
  */
90
90
  async execute(query, bindValues) {
91
- const [rowsAffected, lastInsertId] = await primitives.invoke("plugin:sql|execute", {
91
+ const [rowsAffected, lastInsertId] = await core.invoke("plugin:sql|execute", {
92
92
  db: this.path,
93
93
  query,
94
94
  values: bindValues ?? [],
@@ -117,7 +117,7 @@ class Database {
117
117
  * ```
118
118
  */
119
119
  async select(query, bindValues) {
120
- const result = await primitives.invoke("plugin:sql|select", {
120
+ const result = await core.invoke("plugin:sql|select", {
121
121
  db: this.path,
122
122
  query,
123
123
  values: bindValues ?? [],
@@ -136,7 +136,7 @@ class Database {
136
136
  * @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
137
137
  */
138
138
  async close(db) {
139
- const success = await primitives.invoke("plugin:sql|close", {
139
+ const success = await core.invoke("plugin:sql|close", {
140
140
  db,
141
141
  });
142
142
  return success;
package/dist-js/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { invoke } from '@tauri-apps/api/primitives';
1
+ import { invoke } from '@tauri-apps/api/core';
2
2
 
3
3
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
4
4
  // SPDX-License-Identifier: Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-sql",
3
- "version": "2.0.0-alpha.4",
3
+ "version": "2.0.0-beta.0",
4
4
  "description": "Interface with SQL databases",
5
5
  "license": "MIT or APACHE-2.0",
6
6
  "authors": [
@@ -21,7 +21,7 @@
21
21
  "LICENSE"
22
22
  ],
23
23
  "dependencies": {
24
- "@tauri-apps/api": "2.0.0-alpha.12"
24
+ "@tauri-apps/api": "2.0.0-beta.0"
25
25
  },
26
26
  "scripts": {
27
27
  "build": "rollup -c"