#split #sql #sqlite

sql_split

Split a string wtih multiple sqlite sql statements into separate strings

2 releases

0.1.1 Apr 26, 2022
0.1.0 Apr 26, 2022

#1349 in Database interfaces

Download history 1/week @ 2024-11-13 2/week @ 2024-11-20 1/week @ 2024-11-27 4/week @ 2024-12-04 12/week @ 2024-12-11 9/week @ 2025-01-08 5/week @ 2025-02-05 10/week @ 2025-02-12 26/week @ 2025-02-19 28/week @ 2025-02-26

69 downloads per month

MIT license

19KB
343 lines

sql_split

Split a string into individual sqlite sql statements.

This package is a library that contains some routines for managing multiple sql statements in a string. sqlite silently ignores multiple statements when it only expects one. The popular rusqlite also does this.

use sql_split::split;
use rusqlite::{Connection, Result};

let conn = Connection::open_in_memory().expect("Can't open db in memory");
let sql = "CREATE TABLE foo (bar text); CREATE TABLE meep (moop text)";
for s in split(sql) {
    conn.execute(&s, []).expect("Can't write to the db");
}

In addition to basic sql statement splitting, there are functions to count the number of statements, a short-cutting function that tries to quickly tell you if you have more than one statement, and a short-cutting function that only tries to split out the first n statements.

License: MIT


lib.rs:

Split a string into individual sqlite sql statements.

This package is a library that contains some routines for managing multiple sql statements in a string. sqlite silently ignores multiple statements when it only expects one. The popular rusqlite also does this.

use sql_split::split;
use rusqlite::{Connection, Result};

let conn = Connection::open_in_memory().expect("Can't open db in memory");
let sql = "CREATE TABLE foo (bar text); CREATE TABLE meep (moop text)";
for s in split(sql) {
    conn.execute(&s, []).expect("Can't write to the db");
}

In addition to basic sql statement splitting, there are functions to count the number of statements, a short-cutting function that tries to quickly tell you if you have more than one statement, and a short-cutting function that only tries to split out the first n statements.

No runtime deps