Skip to content

Instantly share code, notes, and snippets.

@Code-Hex
Last active August 29, 2015 14:20
Show Gist options
  • Save Code-Hex/07943d9275166b997407 to your computer and use it in GitHub Desktop.
Save Code-Hex/07943d9275166b997407 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use DBI;
use Teng;
use Teng::Schema::Loader;
my $dbh = DBI->connect('dbi:SQLite:quickstart.sqlite','','',{
RaiseError => 1,
PrintError => 0,
AutoCommit => 1,
sqlite_unicode => 1,
});
my $teng = Teng::Schema::Loader->load(
dbh => $dbh,
namespace => 'MyApp::DB',
);
$teng->do(q{
CREATE TABLE user (
id INT UNSIGNED NOT NULL PRIMARY KEY,
name VARCHAR NOT NULL,
age INT UNSIGNED NOT NULL
)
});
# PRIMARY KEY制約が設定されたカラムには重複した値を格納することはできません。
# ただしnullは複数のカラムに格納が可能です。
# NOT NULL成約が設定されたカラムにはNULLを格納することができなくなります。
# NULL NULL値
# INTEGER 符号付整数。1, 2, 3, 4, 6, or 8 バイトで格納
# REAL 浮動小数点数。8バイトで格納
# TEXT テキスト。UTF-8, UTF-16BE or UTF-16-LEのいずれかで格納
# BLOB Binary Large OBject。入力データをそのまま格納
# http://so-zou.jp/web-app/tech/database/sqlite/data/data-type.htm
@Code-Hex
Copy link
Author

$ sqlite3 quickstart.sqlite
sqlite> .exit
$ perl makeschema.pl
$ sqlite3 quickstart.sqlite
sqlite> .schema
sqlite> .exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment