Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Info Laravel Package

atlas/info

Atlas.Info discovers and exposes database schema information using an Atlas.Pdo Connection. Inspect tables, columns, indexes, and other metadata programmatically to support migrations, tooling, and code generation. Documentation: http://atlasphp.io/cassini/info/

View on GitHub
Deep Wiki
Context7

Usage

Instantiation

Create an information-discovery object with a corresponding connection:

use Atlas\Info\Info;
use Atlas\Pdo\Connection;

$connection = Connection::new('sqlite::memory:');
$info = Info::new($connection);

Note:

The new() method will automatically pick the right schema-discovery class for your Connection.

Fetching Table Names

To get an array of table names from the current schema, call fetchTableNames().

$tableNames = $info->fetchTableNames();
foreach ($tableNames as $tableName) {
    echo $tableName . PHP_EOL;
}

You can also indicate that you want table names from another schema:

$tableNames = $info->fetchTableNames('schema_name');

Fetching Column Defintions

To get an array of column definitions in a table, call fetchColumns().

$columns = $info->fetchColumns('table_name');
foreach ($columns as $name => $def) {
    echo "Column $name is of type "
       . $def['type']
       . " with a size of "
       . $def['size']
       . PHP_EOL;
}

Tip:

You can use a schema prefix on the table name if you like, such as 'schema_name.table_name'.

Each element is itself an array, with the following keys:

  • name: (string) The column name

  • type: (string) The column data type. Data types are as reported by the database.

  • size: (?int) The column size (character length for strings, or numeric precision for numbers).

  • scale: (?int) The number of decimal places for the column, if any.

  • notnull: (bool) Is the column marked as NOT NULL?

  • default: (mixed) The default value for the column. Note that this will be null if the underlying database uses an SQL expression instead of a literal string or number.

  • autoinc: (bool) Is the column auto-incremented?

  • primary: (bool) Is the column part of the primary key?

Fetching Auto-Increment Sequence Name

To fetch the name of the primary key autoincrement sequence on a PostgreSQL table, call fetchAutoincSequence() with the table name.

$sequence = $info->fetchAutoincSequence('table_name');
// => 'table_name_id_seq'

On systems other than PostgreSQL, this will return null.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log