NAME
Yancy::Backend::Sqlite - A backend for SQLite using Mojo::SQLite
VERSION
version 1.078
SYNOPSIS
### URL string
use Mojolicious::Lite;
plugin Yancy => {
backend => 'sqlite:data.db',
read_schema => 1,
};
### Mojo::SQLite object
use Mojolicious::Lite;
use Mojo::SQLite;
plugin Yancy => {
backend => { Sqlite => Mojo::SQLite->new( 'sqlite:data.db' ) },
read_schema => 1,
};
### Hashref
use Mojolicious::Lite;
plugin Yancy => {
backend => {
Sqlite => {
dsn => 'sqlite:data.db',
},
},
read_schema => 1,
};
DESCRIPTION
This Yancy backend allows you to connect to a SQLite database to manage the data inside. This backend uses Mojo::SQLite to connect to SQLite.
See Yancy::Backend for the methods this backend has and their return values.
Backend URL
The URL for this backend takes the form sqlite:<filename.db>
.
Some examples:
# A database file in the current directory
sqlite:filename.db
# In a specific location
sqlite:/tmp/filename.db
Schema Names
The schema names for this backend are the names of the tables in the database.
So, if you have the following schema:
CREATE TABLE people (
id INTEGER PRIMARY KEY,
name VARCHAR NOT NULL,
email VARCHAR NOT NULL
);
CREATE TABLE business (
id INTEGER PRIMARY KEY,
name VARCHAR NOT NULL,
email VARCHAR NULL
);
You could map that to the following schema:
{
backend => 'sqlite:filename.db',
schema => {
People => {
required => [ 'name', 'email' ],
properties => {
id => {
type => 'integer',
readOnly => 1,
},
name => { type => 'string' },
email => { type => 'string' },
},
},
Business => {
required => [ 'name' ],
properties => {
id => {
type => 'integer',
readOnly => 1,
},
name => { type => 'string' },
email => { type => 'string' },
},
},
},
}
SEE ALSO
AUTHOR
Doug Bell <preaction@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.